The effect you see is invoked by directx or other low level libs.
The effect is this: Fullscreen bzw. real hardware access means total control
about the gfx card.
If you change to another application (or desktop - thats also a
application),
then you lose control - and all what you have done with the cards memory.
This includes
of course every suface, you had allocated from hardware ram of your gfx
card. DirectX/Sdl
will remember size and settings of your surfaces - but the content will be
kicked.
Look in the doku under SDL_BltSurface. If you lose your hardware access,
this routine
(and all others which use a surface) will return -2 when you try to blit. If
you press Alt/tab
when using a fullscreen app, this app is not stopped. The main loop
inclusive all blts runs on!
But instead of blt to some card memory, the routines returns with -2. If you
think about it,
you will now understand one reason of locking/unlocking surfaces too.
The reason why the application itself must care about relloading the
surfaces and not
the directx/sdl lib is simple too. First, it is to hard to resynchronize
complexer accesses-
for example when you change surfaces by the application. When you give the
focus back to your app,
it must then track back exactly the point where you lost it. You will need a
complex communication
system between OS, driver and application to really get the point, the
application lose
focus. Remember, that this can happens at EVERY point of your application -
every single blit, every
loop. Btw, thats one reason why you block the whole OS when you lock a
surface under directx.
And thats a reason why it is not allowed under linux.
Because there are too many side effects, the low level drivers like DX goes
the direct way.
Kick the memory and tell the application that it need to reallocate.
So, you need to ask inside your blt routine for -2 as SDL_BltSurface()
return and if so, you has
lose gfx card memory control.
THEN you should not try to direct reallocate the memory - ask first the OS
about who has the
focus now. If your app has then back (after pressing the alt/tab again),
then you can reinit the
surfaces.>
Hi all,
What is the preferred way of restoring lost surfaces when using SDL.
Under DirectX when the user alt-tabbed away from the game and alt-tabbed
back, I had to repopulate the DirectX surfaces.
Do the same rules apply with SDL or is there another way this is done
that I have missed.
Thanks,
Dominique.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl