Lost surfaces

I’m having trouble with lost surfaces. I’m using Windows 95 with DirectX,
and SDL version 1.1.3. I call SDL_SetVideoMode with SDL_HWSURFACE |
SDL_FULLSCREEN | SDL_DOUBLEBUF. In my draw_bitmap function, I do the
following.

for (int i = 0; i < 2; i++) {
  if (bitmaps[n] && SDL_BlitSurface(bitmaps[n], &source, surface, &dest)

!= -2)
return;
SDL_PumpEvents();
if (!(SDL_GetAppState() & SDL_APPACTIVE))
return;
if (!load_bitmaps())
return;
}

For some reason this doesn’t work: when I press alt-tab to switch to a
different program, I am unable to switch back to my SDL application. What
am I doing wrong? Does anybody have working code that allows alt-tab under
Windows with video memory surfaces? Can anybody help me?–
Rainer Deyke (root at rainerdeyke.com)
Shareware action/role-playing games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

In windows, video memory can disappear at any time. Check this page for
more info:
http://www.libsdl.org/docs/video/functions.html

Perhaps the SDL version of windows could have a hack to work around
this? Like when alt-tab is pressed, it could write all the surfaces to
file, and when the application is brought to the foreground again it can
retrieve them. I think it’s unfair for programmers to have to make
accomodations for this direcX “feature”.> ----- Original Message -----

From: owner-sdl@lokigames.com [mailto:owner-sdl at lokigames.com]On Behalf
Of Rainer Deyke
Sent: Saturday, July 08, 2000 9:39 PM
To: sdl at lokigames.com
Subject: [SDL] lost surfaces

I’m having trouble with lost surfaces. I’m using Windows 95 with DirectX,
and SDL version 1.1.3. I call SDL_SetVideoMode with SDL_HWSURFACE |
SDL_FULLSCREEN | SDL_DOUBLEBUF. In my draw_bitmap function, I do the
following.

for (int i = 0; i < 2; i++) {
  if (bitmaps[n] && SDL_BlitSurface(bitmaps[n], &source, surface,

&dest)
!= -2)
return;
SDL_PumpEvents();
if (!(SDL_GetAppState() & SDL_APPACTIVE))
return;
if (!load_bitmaps())
return;
}

For some reason this doesn’t work: when I press alt-tab to switch to a
different program, I am unable to switch back to my SDL application. What
am I doing wrong? Does anybody have working code that allows alt-tab
under
Windows with video memory surfaces? Can anybody help me?

Matt Pekar wrote:

In windows, video memory can disappear at any time. Check this page for
more info:
http://www.libsdl.org/docs/video/functions.html

Perhaps the SDL version of windows could have a hack to work around
this? Like when alt-tab is pressed, it could write all the surfaces to
file, and when the application is brought to the foreground again it can
retrieve them. I think it’s unfair for programmers to have to make
accomodations for this direcX “feature”.

Agreed. I’d personally just tell everyone to be smart and switch to BeOS or
Linux (Note: I’ve never used BeOS, but it’s multimedia and thus game
capabilities and seriously impressed, although I 100% plan to stick to
Linux)… In any case, yes, the unfortunate Windows developers shouldn’t
have to put up with that. The only thing is, is it possible to detect that
Windows is about to throw away the memory before it does so, so that it
CAN be backed up? If not, is it possible to store the ‘source’ of a surface,
so if it is lost, it can be restored? The problem there lies in dynamically
generated images (like light maps), and altered images…

Perhaps a surface could have two extra data members: a ‘reload’ callback, and
a void pointer to arbitrary data. Thus, if SDL detects that Windows, it
could call the callback, with a pointer to the surface and the void pointer
as data. The programmer could put the data needed for loading and
manipulating the image into the void pointer (a structure obviously), and
reload the data. If the programmer was smart, they’d make the normal load
function work just like this, so that they’d just need one function, and it
would work pretty well. They’d just have to be careful about speed (because
if Windows throws the memory away in mid-game operation, the performance hit
would be REALLY big instead of just big…). BTW, does Windows 9x use true
pre-emptive multi-tasking? Back when I first started programming graphical
games (well, after I got sick of writing SVGA drivers in DOS), I had tried
writing DX3 apps in Windows, and I remember something about the Windows app
had to ‘give control back to Windows’ to process events or some-such. In any
case, the description didn’t sound like a normal event collection loop (such
as what I’m familiar with in GTK/X/SDL/etc., they made it sound like Windows
depended on it. I may be way wrong… but anyways… I’m hyper!! How are
you?

There’s my .35 1/3 cents (not that my opinion is worth more, I just think
that I gave a lot more of it than most… IOW, I BS’ed a lot. ~,^ )

Ya.

Sean Etc.

Well, yes, there is such a problem, but most interesting thing that on
some computers there is no such bug.
For me i have solution- when program looses focus and then gains it, i
destroy screen surface, then call SDL_SetVideoMode, and after it, reload
those images which were placed in video memory.
Personally i would recommend to write some resource manager, wich can
load, destroy, re-load images (and make refrence counting if want to use
same picture more than once). After this resource management should
become a little bit easier.

KovacsOn Sat, 8 Jul 2000, Rainer Deyke wrote:

I’m having trouble with lost surfaces. I’m using Windows 95 with DirectX,
and SDL version 1.1.3. I call SDL_SetVideoMode with SDL_HWSURFACE |
SDL_FULLSCREEN | SDL_DOUBLEBUF. In my draw_bitmap function, I do the
following.

for (int i = 0; i < 2; i++) {
  if (bitmaps[n] && SDL_BlitSurface(bitmaps[n], &source, surface, &dest)

!= -2)
return;
SDL_PumpEvents();
if (!(SDL_GetAppState() & SDL_APPACTIVE))
return;
if (!load_bitmaps())
return;
}

For some reason this doesn’t work: when I press alt-tab to switch to a
different program, I am unable to switch back to my SDL application. What
am I doing wrong? Does anybody have working code that allows alt-tab under
Windows with video memory surfaces? Can anybody help me?


Rainer Deyke (root at rainerdeyke.com)
Shareware action/role-playing games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor