I've made a function to load a bitmap and give me a pointer to it.
Code:
void loadBMP(char *fname, SDL_Surface *bmp)
{
SDL_Surface *tmp = SDL_LoadBMP(fname);
char msg[256];
if (tmp == NULL) {
sprintf (msg, "Couldn't initialize: %s\n", SDL_GetError ());
MessageBox (0, msg, "Error", MB_ICONHAND);
return;
}
bmp = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
}
But it only seems to stay allocated within the function for some reason.
e.g. if I do
Code:
sprintf(msg, "%d", bmp->w);
MessageBox (0, msg, "Error", MB_ICONHAND);
from within the function, it gives me the width of the bitmap, however if I call that outside the function
Code:
SDL_Surface *bitmap;
loadBitmap("block.bmp", bitmap);
sprintf(msg, "%d", bitmap->w);
MessageBox (0, msg, "Error", MB_ICONHAND);
It crashes the program. How can I stop the data from being garbage collected?