I am trying to load a bitmap image into a program with SDL. When I run the
following short program or whenever the function SDL_ConvertSurface() is
called the program stops responding. Through Xcode’s debugger I have found
that it is giving the error: EXC_BAD_ACCESS, which I have read has something
to do with memory, but I do not know how I can change how
SDL_ConvertSurface() deals with memory.
Here is my code:
#include “SDL/SDL.h”
int main( int argc, char *argv[] ){
// Screen surface
SDL_Surface *gScreen, *gTiles;
// Initialize SDL's subsystems
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
// Attempt to create a 320x240 window with 32bit pixels.
gScreen = SDL_SetVideoMode(320, 240, 32, SDL_SWSURFACE);
// Load tiles.bmp into the temp surface, then convert it to the format of
gScreen and save it to gTiles, then free the temp surface
SDL_Surface *temp = SDL_LoadBMP(“tiles.bmp”);
gTiles = SDL_ConvertSurface(temp, gScreen->format, SDL_SWSURFACE);
SDL_FreeSurface(temp);
return 0;
}
All this does is load a .bmp, convert it, save it to a new surface, then
free the temp surface and exit. Unfortunately when I run this all it does
is hang. When I step through it in the debugger I then get the
EXC_BAD_ACCESS error.
When looking up things to make sure I wasn’t asking a common question I
learned that I needed to add the SDL_Init() line before calling
SDL_ConvertSurface(), but that did not change my results.
I am using SDL 1.2.13 for Mac OS X Leopard 10.5.2 and Xcode 3.0. When
running programs with this same section of code in Windows I do not get this
error.
Thank you for your help,
-rob–
View this message in context: http://www.nabble.com/EXC_BAD_ACCESS-on-SDL_ConvertSurface-Mac-OS-X-tp15753087p15753087.html
Sent from the SDL mailing list archive at Nabble.com.