PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Maybe a problem with 2.0 on the desktop

One of my beta users just noticed that if you run Pocket War full screen and then alt-tab out, when you alt-tab back in the screen is blank (bascially it stops updating.) This worked fine in 110b2 and it still works fine on Pocket PCs (no alt-tab but you can minimize there) it only seems to happen full screen on the desktop.

Any thoughts?
Yes,

One or more of the surfaces (probably the back buffer) are stored in video memory and have been lost when you switched to the desktop. The reason for this behaviour is that it will work exactly the same if a game runs on a hardware-accelerated PDA and is minimized...

You can simply call CGapiDisplay::SurfacesAreLost() on each ProcessNextFrame(). If it returns GDERR_LOSTSURFACE one or more video surfaces have been destroyed. You can then call CGapiDisplay::RestoreAllSurfaces() to restore all video surfaces (unfortunately the contents of the surfaces have also been destroyed and you need to reload all bitmaps etc using CreateSurface again - GapiDraw will not reallocate memory if the surface size hasn't changed if CreateSurface is called multiple times).

It's a good idea to not check for lost surfaces and restore them if the application is minimized (since restoring the backbuffer will fail on each try).

I'm currently working on a detailed documentation on the HW implementation, with a number of "do"s and "don't"s...
I allocate all my surfaces in system memory not video memory. So I am guessing that the only surface I lost was the backbuffer?

I still have this chunk of code

Code:

if( g_display.Flip() == GDERR_BACKBUFFERLOST )
{
g_display.GetBackBuffer( &g_backbuffer );
}


in my program. Does that code not work any more? Also, if all I lost was the backbuffer and everything else is allocated as GDSURFACE_SYSTEMMEMORY do I still need to rebuild all my images. (That would hurt as Pocket War has over 500 images and it takes some time to set them all up when the game first starts.)
Unfortunately you still need to check if the back buffer was relocated during the Flip(). It can only be relocated on some GAPI implementations, and as of yet no GAPI-implementation is known to do so (but that might change). Perhaps if it was called "GDERR_GAPIBUFFERLOST" it would be a better term... Hmm...

Actually.. I think I'll change the description of GDERR_BACKBUFFERLOST to GDERR_GAPIBUFFERLOST in gapidraw.h when I add documentation to the GapiDraw 2.00 package.. Then it's more clear of what's happening...

If all surfaces except the back buffer are located in system memory you don't need to re-create them.. You only need to call CreateSurface() again on those that are located in video memory... By the way. If you do any alpha blends (opacity etc) on the backbuffer you will get a real speedup if you store that one also in system memory (GDDISPLAY_BACKBUFFERSYSMEM).

I really, really need to finish document with all these things listed soon...
Hm. Perhaps GDERR_GAPIBACKBUFFERLOST is even better. Then it's more clear why the back buffer instance should be re-initialized... I think I'll go with that one...
I just checked I do put GDDISPLAY_BACKBUFFERSYSMEM in my opendisplay call.
tedson: Um.. I forgot. The front buffer is also lost when you switch to the desktop. So if all surfaces (including back buffer) is stored in sysmem you can simply add:

if (GDERR_LOSTSURFACES == m_display.SurfacesAreLost())
m_display.RestoreAllSurfaces();

... last in each frame update when your application is not minimized.
Yup that fixed it. In case others are reading this thread here is the code...

Code:

if( GDERR_SURFACELOST == display.SurfacesAreLost() )
display.RestoreAllVideoSurfaces();


Only slightly different then what Johan remembered. :)