Locked Surface during Blit?

Alright, Back to the blitting again…
I made a little breakthrough, for some odd reason my program doesn’t
like to check for errors when it’s in full screen.

I brought it in to windowed mode and it sang like a bird.
And the only error I got was(The one that made me seg) “Surfaces must not
be locked during blit”

What? I thought they had to be.
So I tried Unlocking them… And I don’t think I’m doing it right.
Here is the code where the error happens (according to gdb)

void HUD::DRAW(SDL_Surface *screen) {
SDL_UnlockSurface(energy_bar);
if(SDL_BlitSurface(energy_bar, NULL, screen, &e_bar_rect) == -1) { <----
Ding ding ding
LOG.WRITE(SDL_GetError());
exit(1);
}
SDL_LockSurface(energy_bar);
SDL_UnlockSurface(health_bar);
if(SDL_BlitSurface(health_bar, NULL, screen, &h_bar_rect) == -1) {
LOG.WRITE(SDL_GetError());
exit(1);
}
SDL_LockSurface(health_bar);
}

Help? :slight_smile:
-Bryan Arant

And the only error I got was(The one that made me seg) “Surfaces must not
be locked during blit”

What? I thought they had to be.
So I tried Unlocking them… And I don’t think I’m doing it right.

You need to lock a surface to get direct access to the pixel data. You
should unlock it when you’re done manipulating it.

i.e.
SDL_LockSurface (energy_bar);
… stuff that reads/modifies energy_bar->pixels …
SDL_UnLockSurface (energy_bar);

So if you’re updating the bars using direct pixel manipulation, that’s the
only time it should be locked. Unlock it when you’re done and then just blit
it.

When you unlock the surface, SDL can then encode it into whatever format is
best for the video surface format you’re using, etc. When you lock it, SDL
makes sure the surface->pixel buffer is not encoded so you can manipulate it
without worrying about RLE or anything like that.

So once again, nice and short:
The ONLY time you need to lock the surface is when you’re directly
manipulating the surface->pixels buffer. You should then unlock it
immediately after you’re done doing that.

Hope this clears things up :-)On Thu, 3 Jan 2002, Bryan Arant wrote:

Mike.

Don’t know if this will help but you can try using the
SDL_MUSTLOCK(SDL_SURFACE *screen) macro to check to see if your surface
needs to be locked. If it returns TRUE, lock the surface, else just
continue your code without locking. Just make sure that if you locked
the surface, unlock it before blitting.

Hope this helps,
Jason Brunson> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Bryan Arant
Sent: Thursday, January 03, 2002 2:06 AM
To: sdl at libsdl.org
Subject: [SDL] Locked Surface during Blit?

Alright, Back to the blitting again…
I made a little breakthrough, for some odd reason my program doesn’t
like to check for errors when it’s in full screen.

I brought it in to windowed mode and it sang like a bird.
And the only error I got was(The one that made me seg) “Surfaces must
not
be locked during blit”

What? I thought they had to be.
So I tried Unlocking them… And I don’t think I’m doing it right.
Here is the code where the error happens (according to gdb)

void HUD::DRAW(SDL_Surface *screen) {
SDL_UnlockSurface(energy_bar);
if(SDL_BlitSurface(energy_bar, NULL, screen, &e_bar_rect) == -1) {
<----
Ding ding ding
LOG.WRITE(SDL_GetError());
exit(1);
}
SDL_LockSurface(energy_bar);
SDL_UnlockSurface(health_bar);
if(SDL_BlitSurface(health_bar, NULL, screen, &h_bar_rect) == -1) {
LOG.WRITE(SDL_GetError());
exit(1);
}
SDL_LockSurface(health_bar);
}

Help?:slight_smile:
-Bryan Arant


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl