CSprite::CSprite(string sprite_fname) {
frames = 0;
current = 0;
timer = 0;
oldx = 0;
fstream sprite_file(sprite_fname.c_str());
while (!sprite_file.eof()) {
string image_fname;
int pause;
sprite_file >> image_fname;
sprite_file >> pause;
anim_v.push_back(XFrame(SDL_LoadBMP(image_fname.c_str()), pause));
SDL_SetColorKey (
anim_v[frames].image,
SDL_SRCCOLORKEY,
SDL_MapRGB(anim_v[frames].image->format, 255, 0, 255)
);
frames++;
}
}
SDL_SetColorKey ...
hello, ive decied to give SDL a try after using opengl for a bit, and wow it's much easier (for 2d of course) but why does SDL_SetColorKey crash my program!
if i comment out SDL_SetColorKey part it works perfectly fine ... i try to make temp copies and try to apply SetColorKey to that then push_back the anim vector, but no matter what it crashes the program. im new to sdl so im probably missing something trivial.
thanks for any help in advance.
Try loading the surface, applying the colorkey, THEN pushing it into the container.
Oh, and check to make sure SDL_LoadBMP doesn't return 0 or something.
Oh, and check to make sure SDL_LoadBMP doesn't return 0 or something.
Maybe, just maybe, anim_v[frames] is causing an access violation? (The index is out of range?)
Given that code it shouldn't be.
Er... actually. OP, you might be suffering from .eof() problems.
I think that it'll come around, say it's NOT eof, then it'll try to read a filename, get nothing back and set the eof bit, then you try to open "", which of course, fails. then you try to access it, and it dies.
try redoing the loop like
while(sprite_file >> fname >> pause) { ..... }
(but you should still redo the loop like I suggested before, since a missing file will cause it to crash unless you change it like I suggested.)
Er... actually. OP, you might be suffering from .eof() problems.
I think that it'll come around, say it's NOT eof, then it'll try to read a filename, get nothing back and set the eof bit, then you try to open "", which of course, fails. then you try to access it, and it dies.
try redoing the loop like
while(sprite_file >> fname >> pause) { ..... }
(but you should still redo the loop like I suggested before, since a missing file will cause it to crash unless you change it like I suggested.)
i tried using color key before pushing it into the container and it still didnt work (didnt have to use frames as index either) ... also the files do load properly, obiovusly just with a bright pink background around them. image is declared as SDL_Surface * and is part of the XFrame struct (i also un-nested this class, but still didnt work).
also it seems i can apply the color key to the entire screen .. which isnt much use, but anything else and it crashes.
also it seems i can apply the color key to the entire screen .. which isnt much use, but anything else and it crashes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement