Hello,
I’m getting a weird segmentation fault (and the corresponding SDL parachute)
while doing what would seem to be a basic loading of "a lot of png images"
into an array using the IMG_Load function.
So, I reduce my program to the absolute minimum that still reproduces the
seg fault:
Here is the code of the loading module (assuming sdl was init correctly):
-------------------->
/* Declaration of the array: */
SDL_Surface *array_fonts[500];
/* Loading function: */
static SDL_Surface *LoadSurface(char *filename) {
SDL_Surface *surface;
surface=IMG_Load(filename);
if (!surface) {
/* never reached */
fprintf(stderr,"Error! Reason: %s\n",IMG_GetError());
exit(EXIT_FAILURE);
}
return surface;
}
/* main - Put 550 SDL_Surface pointers into array_fonts :*/
array_fonts[0]=LoadSurface(“gfx/0.png”);
array_fonts[1]=LoadSurface(“gfx/1.png”);
…
…
…
array_fonts[498]=LoadSurface(“gfx/498.png”);
array_fonts[499]=LoadSurface(“gfx/499.png”);
<--------------------
After debugging, the segmentation fault occurs while loading the 421th image
(at line ‘surface=IMG_Load(filename)’).
If I delete the line corresponding to this image, the seg fault will occur to
the 422th image etc.
I have tried using the IMG_LoadPNG_RW function and I got the same result.
I have also tested all the image data to see if they are readable as PNG
(using IMG_isPNG function) and it’s the case.
The segfault only occurs on Windows. I’m using SDL-1.2.7 and SDL_image-1.2.3
with VisualC++ 6.0 Standard Edition on Windows XP. Moreover, I’ve tested this
program on different computers using Windows and the seg fault also occurs.
Note that this code works perfectly under Linux.
Is my code okay ? Any idea will be really appreciated !
Thanks.