| View previous topic :: View next topic |
| Author |
Message |
r0b3rt
Joined: 26 May 2008 Posts: 17
|
Posted: Mon Jun 16, 2008 9:32 pm Post subject: Error loading 11th file (SDL_image) |
|
|
Hi, I have a strange problem. I am using this function to load and display image files using SDL, and everything works fine for the first 10 files.
When I try to display the 11th image, I get a: "Couldn't open name_of_the_image.bmp". And it doesn't matter if I'm displaying small or full screen images. I'm also monitoring amount of free memory and I think there's no problem there.
| Code: |
int displayImageUsingSDL(SDL_Surface *screen, const char* imageName, int posX, int posY){
SDL_Surface *image = NULL;
SDL_RWops *rwop = NULL;
rwop=SDL_RWFromFile(imageName, "rb");
image=IMG_LoadBMP_RW(rwop);
if(!image){
pspDebugScreenInit();
pspDebugScreenPrintf("ERROR: %s\n", IMG_GetError());
return -1;
}
//else drawtile(image, 0, 0, image->w, image->h, posX, posY, 0, 0, screen);
//sceDisplayWaitVblankStart();
//SDL_Flip(screen);
SDL_FreeRW(rwop);
SDL_FreeSurface(image);
return 0;
}
|
So any idea where is the problem?
In the main program I have this:
| Code: |
while(1){
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CIRCLE) break;
else if(pad.Buttons & PSP_CTRL_CROSS) displayImageUsingSDL(screen, "fullscreen.bmp", 0, 0);
else if(pad.Buttons & PSP_CTRL_TRIANGLE) displayImageUsingSDL(screen, "small.bmp", 0, 0);
else if(pad.Buttons & PSP_CTRL_SQUARE) printMemory();
SDL_Delay(100);
}
|
|
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Mon Jun 16, 2008 9:45 pm Post subject: |
|
|
| Are you using PSP_HEAP_SIZE_KB(20480); or similar in your code to give yourself some heap to allocate from? |
|
| Back to top |
|
 |
r0b3rt
Joined: 26 May 2008 Posts: 17
|
Posted: Mon Jun 16, 2008 10:28 pm Post subject: |
|
|
| Yes, i am using PSP_HEAP_SIZE_KB(10240); |
|
| Back to top |
|
 |
r0b3rt
Joined: 26 May 2008 Posts: 17
|
Posted: Mon Jun 16, 2008 10:35 pm Post subject: |
|
|
I am using these 3 ways to determine the amount of free memory (found 2 here, coded the third one myself):
| Code: |
void printMemory(){
SceSize am = sceKernelTotalFreeMemSize();
struct mallinfo mi;
int mem, *myPtr = NULL, *myOldPtr = NULL, size = 64;
mi = mallinfo();
mem = (10240*1024) - mi.arena + mi.fordblks;
pspDebugScreenPrintf("Available memory (heap size): %dbytes (%dKB or %dMB)\n", am, am/1024, am/1024/1024 );
pspDebugScreenPrintf("Available memory: %dbytes (%dKB or %dMB)\n", mem, mem/1024, mem/1024/1024 );
while(1){
myPtr = (int*)realloc(myPtr, size);
if (!myPtr){
free(myOldPtr);
size -= 64;
break;
}
else{
myOldPtr = myPtr;
size += 64;
}
}
pspDebugScreenPrintf("Available memory (by me): %dbytes (%dKB or %dMB)\n", size, size/1024, size/1024/1024 );
}
|
They are telling me I have 14/10/5 MB of memory free.
The values change only slightly after loading 10 images. |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Mon Jun 16, 2008 10:43 pm Post subject: |
|
|
| Try setting the heap to 20480 and post back with your results. |
|
| Back to top |
|
 |
r0b3rt
Joined: 26 May 2008 Posts: 17
|
|
| Back to top |
|
 |
crazyc
Joined: 17 Jun 2005 Posts: 410
|
Posted: Mon Jun 16, 2008 11:55 pm Post subject: |
|
|
| I bet the files arn't being closed after you are done with them. |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Tue Jun 17, 2008 1:13 am Post subject: |
|
|
Nice catch crazyc.
Add:
|
|
| Back to top |
|
 |
r0b3rt
Joined: 26 May 2008 Posts: 17
|
Posted: Tue Jun 17, 2008 5:55 pm Post subject: |
|
|
Thanks for the help, works fine now.
Strange it crashed at the 11th file - I guess there's a limit on a number of opened SDL_RWops.
Thanks again. |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Tue Jun 17, 2008 7:36 pm Post subject: |
|
|
| The limit is on the PSP, which is 10 open files. |
|
| Back to top |
|
 |
|