Sign in to follow this  

[SDL] Locked Surface issue? (Blit = Crash)

Recommended Posts

Hello everyone, I've been building a small GameEngine for about a month now but recently have re-written it in a more efficient way and cleaner code ofcourse. And I used a new draw method as my old one was rusty, it works perfectly until I switch from the main function (where the screen first was inited) to lets say the StartMenu function, and there whenever I try to touch gameScreen (the gamescreen surface) with SDL_Flip for example it crashes the whole game, unless I re-initialize the screen in that function as well which seems like complete rubbish to do.. I can't find a solution to this problem, I tried checking whether it was locked or not, tried unlocking it with SDL_UnlockSurface, yet nothing. And when I cout SDL_Error it says that the surface shouldn't be locked while blitting.. ;/ I'll include the source of the core with as less code as possible to point out the issue; core.cpp; core.h; main.cpp; [Ah, sorry I forgot to comment that on line 24 we leave main.cpp to startscreen.cpp where all the black magic happens that is the cause of the crash, just in case thought I'd say >_<] startscreen.cpp; I started programming a few months back on school and now am working on this personal project which I am hoping to create a few small games with and learn SDL a bit further, but this is one of the first things I wasn't able to solve even after a good search on google.. >_< Does any one of you see the error I made? Thanks in advance for taking your time!

Share this post

Link to post
Share on other sites
A few questions. First, in the class header, why is there the [1] at line 7, and why is it commented out? Surely, if it wasn't commented out, it would produce a compiler error, but did you just comment it out when posting it, or is it always commented out?

SDL_Surface *gameScreen; //[1]

Second, could you post the code for your drawing function?

Also, do you use the SDL_Locksurface/SDL_Unlocksurface/SDL_MUSTLOCK functions anywhere? (With the exception of when you tried to check in your blitting function)

Finally, try removing the flag 'SDL_DOUBLEBUF' from your SDL_SetVideoMode(...) and, rebuilding the program, tell us if it fixes anything. It'd help narrow down your problem.

Share this post

Link to post
Share on other sites
I doubt I can make the surface gameScreen an array.. ;p But no, the [1] simply meant CommentBlock one, you see I don't like huge blocks of comments between header files, so I mark them with numbers, and then on the bottom of the header file I make the huge comment labeled as 1.

And I haven't used ANY SDL's LockSurface commands anywhere, since I got the error of the surface being locked I tried to use SDL_UnlockSurface but that didn't help, but other than that I barely knew they existed

My image drawing code is in the core, but I'll post my loading function as well as it's part of the drawing function.

[Drawing function]

[Loading Function

[Graphics class]

Finally I removed SDL_DOUBLEBUF, and it seemed to fix the crash, but I still get the locked surface error, it doesn't blit anything in startScreen anymore, unless I re-initialize the screen again ofcourse but that's not needed since that never happened before..

Wait, removing the SDL_DOUBLEBUF didn't fix the crash, somehow when I std::cout SDL_GetError the whole thing doesn't crash, and when I remove it it does crash, what the.. This is the weirdest situation I've been in >_<

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this