[SDL] The "proper" way to detect an app context switch

Kylotan kylotan at kylotan.eidosnet.co.uk
Tue Sep 10 11:51:01 PDT 2002

Neil Bradley wrote:
> I've got a full screen SDL based app that I'd like to pause (stop
> blitting, stop sound, etc...) when the context is switched away. I've
> read that one way of doing so is checking to see whether or not a
> blit fails, and if it does, pause.

Although Sam already provided the correct answer, there's one more
thing... I believe the 'blit failure' method of detecting a context
switch is just a side-effect of the fact that DirectX has a tendency to
lose its surfaces when another application takes the focus. Therefore
you won't always get this failure on Windows, and I don't know if you
get it at all on platforms that do better surface management than
DirectX does. From the docs I have:

"If either of the surfaces were in video memory, and the blit
returns -2, the video memory was lost, so it should be reloaded with
artwork and re- blitted. [...] This happens under DirectX 5.0 when the
system switches away from your fullscreen application. Locking the
surface will also fail until you have access to the video memory again."


More information about the SDL mailing list