I'm try to learn SDL lib,
I've coded a simple JPG image loader,
it works great but if I try to load 10-15 images
I've a error (Error while loading image...)
I've try to look on the disponible RAM and when I load a image a part of RAM is normally allocated, but when I exit the function the RAM is not free correctly!!!
Please, help....
Here is the code:
Code: Select all
int Image_viewer(char* target)
{
SDL_Surface *background = NULL; // Image surface
SDL_Surface *screen = NULL; // Screen surface
SDL_Init(SDL_INIT_EVERYTHING);
SDL_ShowCursor(0);
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
SDL_RWops* rwfile = SDL_RWFromFile(target, "rb");
background = IMG_LoadJPG_RW(rwfile);
if( background != NULL )
{
//Create an optimized image
background = SDL_DisplayFormat(background);
}
else
{
Init();
printf("\nError while loading image...");
sleep(2000000);
SDL_FreeSurface(background);
SDL_FreeSurface(screen);
SDL_FreeRW(rwfile);
SDL_Quit();
initGraphics();
return 1;
}
SDL_FreeRW(rwfile);
// Show the image centered on the screen
//Make a temporary rectangle to hold the offsets
SDL_Rect offset;
//Give the offsets to the rectangle
offset.x = ( screen->w - background->w ) / 2;
offset.y = ( screen->h - background->h ) / 2;
//Blit the surface
SDL_BlitSurface( background, NULL, screen, &offset );
SDL_Flip( screen );
SceCtrlLatch pad;
while(1)
{
sceCtrlReadLatch(&pad);
if(pad.uiMake==PSP_CTRL_CIRCLE)
{
break;
}
}
SDL_FreeSurface(background);
SDL_FreeSurface(screen);
SDL_Quit();
initGraphics();
return 0;
}