GraphicsLost ( )

Parameters

None.

Description

Reports whether the display surfaces have been taken away from the program.

Under DirectDraw and Direct3D 7 the graphics card could reclaim your buffers at any moment - the player alt-tabbed, a screensaver started, another program changed the screen mode - and every drawing command after that went nowhere. GraphicsLost was the flag you checked at the top of your main loop so you could skip the frame, wait, and carry on once Windows handed the surfaces back.

On the modern DirectX 12 backend it always returns 0. There is no lost-device state to report: buffers survive alt-tab, minimising and mode changes, so the condition the command was invented for cannot happen. Old main loops that guard on it still compile and run exactly as before, they simply never take the "lost" branch.

That means you do not need it in new code. If your game pauses when it loses focus, drive that from your own window logic rather than from GraphicsLost, because this will never tell you the window went away. And if you are porting a classic project, leave the guard in - it costs nothing and it documents where the old runtime could stall.

See also: Graphics, Flip, BufferDirty, GfxDriverName, SystemProperty.

Example

; GraphicsLost Example
; --------------------

Graphics 640,480,0,2
SetBuffer BackBuffer()

; A bouncing pickup, so you can see the program is still running
x#=320
y#=240
dx#=2.4
dy#=1.7

frames=0
lost_frames=0

While Not KeyDown(1)

    Cls

    frames=frames+1

    ; The classic Blitz3D guard: if the display surfaces have been
    ; taken away, sit still instead of animating into nothing
    If GraphicsLost() Then
        lost_frames=lost_frames+1
        Delay 100
    Else
        x=x+dx
        y=y+dy
        If x<12 Or x>628 Then dx=-dx
        If y<12 Or y>468 Then dy=-dy
    End If

    Color 80,180,255
    Oval x-12,y-12,24,24,1
    Color 255,255,255

    Text 0,0,"Alt-tab away and back, or minimise the window   Esc: exit"
    Text 0,20,"GraphicsLost() = "+GraphicsLost()
    Text 0,40,"Frames "+frames+"   frames skipped as lost "+lost_frames

    Text 0,420,"On the DirectX 12 backend GraphicsLost always answers 0 - the"
    Text 0,440,"device is never lost, so the guard above never fires and the"
    Text 0,460,"skipped count stays at zero however much you alt-tab."

    Flip

Wend

End

Index