V
voidexp
Hi to all!
I have a strange problem with malloc(). I'm writing a 2D Game Engine,
for learning purposes, and I can't go forward without understanding
the problem... So I have a function:
Sprite* CreateSprite(char *filename);
which accepts a string containing a path to an image (PNG file for
example) and returns a pointer to a struct "Sprite". Nothing complex,
Sprite is a simple typedef for SDL_Surface structure, which is used to
represent surfaces in SDL (a multimedia library), and my function uses
IMG_LoadImage() for data loading. The problem is, when I load some
images (5-6 for example) with a variable size, say from 75k to 500k,
at sixth call of CreateSprite() my program exits with malloc error
message (heap corruption, or something like this). I'm usually
programming in Linux, but the problem persists in windows too. I found
a "solution" to split images in smaller tiles, that aren't greater
than 128k, but it is definetely not a real way to code. Can someone
explain how to fight heap corruption and memory alignment problems?
(This is the cause, as I understood from error messages). Thx to all
and sorry for poor english please
I have a strange problem with malloc(). I'm writing a 2D Game Engine,
for learning purposes, and I can't go forward without understanding
the problem... So I have a function:
Sprite* CreateSprite(char *filename);
which accepts a string containing a path to an image (PNG file for
example) and returns a pointer to a struct "Sprite". Nothing complex,
Sprite is a simple typedef for SDL_Surface structure, which is used to
represent surfaces in SDL (a multimedia library), and my function uses
IMG_LoadImage() for data loading. The problem is, when I load some
images (5-6 for example) with a variable size, say from 75k to 500k,
at sixth call of CreateSprite() my program exits with malloc error
message (heap corruption, or something like this). I'm usually
programming in Linux, but the problem persists in windows too. I found
a "solution" to split images in smaller tiles, that aren't greater
than 128k, but it is definetely not a real way to code. Can someone
explain how to fight heap corruption and memory alignment problems?
(This is the cause, as I understood from error messages). Thx to all
and sorry for poor english please