[SDL] pixels getting set to NULL
Warren Schwader
warrens at sierratel.com
Tue Dec 9 17:46:00 PST 2003
Hi John, Thanks for the excellent explanation and tips. I could have swore
that I tried Locking and unlocking the dialog surface and pixels were still
null, but perhaps something else wasn't quite right for that test.
I did what you suggested to the test code that I previously posted and it
worked. Thanks again!
--Warren Schwader
----- Original Message -----
From: "John Popplewell" <john at johnnypops.demon.co.uk>
To: <sdl at libsdl.org>
Sent: Tuesday, December 09, 2003 1:57 PM
Subject: Re: [SDL] pixels getting set to NULL
> Hi,
>
> On Tuesday 09 December 2003 12:43 pm, Warren Schwader wrote:
> > OK, Sorry for the recent floods of emails, but for those interested I
> > think I fixed my problem,
> > If I use SDL_RLEACCEL when I create the doneImageSurface (one of the
dialog
> > items) then I get the null pixels pointer after blitting the dialog
surface
> > to the main surface. I can still use RLE on the dialog surface though
> > which is good.
> >
> > I guess the only thing still that I need explained is why this is so?
> > --Warren Schwader
>
> In a nut-shell, dialogSurface->pixels isn't guaranteed to be valid
*except*
> when you are inside a Lock<->Unlock block:
>
> SDL_LockSurface(dialogSurface);
> // dialogSurface->pixels valid inside here
> SDL_UnlockSurface(dialogSurface);
> // dialogSurface->pixels no longer valid
>
> RLE surfaces are a good example of why this is so. When you do this:
>
> SDL_SetColorKey(dialogSurface, SDL_SRCCOLORKEY|SDL_RLEACCEL, color);
>
> the memory representing the pixels is compresed into a series of runs of
> non-transparent pixels, which take up less space and are faster to render.
> The original pixel memory is freed.
>
> When you lock an RLE surface, you are requesting access to the original
pixels
> that no longer exist. SDL_LockSurface() knows this and kindly regenerates
the
> original surface for you from the RLE version, fills in
dialogSurface->pixels
> with a pointer to this temporary surface, and lets you fiddle with the
> pixels.
>
> When you call SDL_UnlockSurface() you are indicating that you have
finished
> fiddling and SDL_UnlockSurface() RLE encodes the modified pixels, destroys
> the temporary surface, and sets dialogSurface->pixels to NULL to prevent
> accidents(!).
>
> Some hardware-surface systems e.g. DirectX are capable of copying surface
data
> between system memory and video memory transparently using the same
> Lock/Unlock trick.
>
> Hope that helps,
>
> cheers,
> John.
> PS calling SDL_SetColorKey() or SDL_BlitSurface() whilst a surface is
locked
> (as you seem to) is a bad idea - see the docs.
> --
>
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list