A driver can reset its GPU channel (Vulkan VK_ERROR_DEVICE_LOST), a GPU can be removed, and a browser can destroy a WebGPU device (GPUDevice.destroy(), or a GPU process crash). Every GPU object the game made is then gone. A game that ignores it would hang in the driver or draw nothing for ever, so the engine reports the loss and stops touching the device. The engine does not recreate the device or the renderers. What the game does next is its own decision: save and leave, or save and start over.
What the engine does
GameInstance.DeviceLost(Action<DeviceLostInfo>) is raised once, on the game's thread, with the backend, the operation that met the loss (for examplevkQueueSubmit2, or null when the device's own signal came first), the reason (Reported,NoProgress,Destroyed,SimulatedorUnknown) and a message.- It fires whichever path meets the loss first: drawing or presenting a frame, an offscreen or presented capture and its readback, a resource, model or environment upload, the game's own GPU calls (catch
GpuDeviceLostExceptionand callgame.ReportDeviceLost(ex)), a control operation, or the device's own lost signal, which can arrive on another thread and is raised on the game's thread at its next frame or control call.game.IsDeviceLostandgame.DeviceLosssay the same afterwards. - After it, the instance makes no further GPU calls: no drawing, no present, no readback, no waiting for the GPU.
Capture,CapturePresentedandDescribeRenderGraphthrowGpuDeviceLostExceptionat once. The window, input, UI layout, simulation ticks, saves, settings, audio and every control operation that does not need the GPU keep working. A frame costs one volatile read for the check. - A device found lost is not lent to the next run: a
GameHostdrops it and its swapchain, and the nextGameInstanceon the host makes a new device.
How soon the event comes
A driver that reports the loss (VK_ERROR_DEVICE_LOST, or the browser's device.lost) is found at once. Some resets report nothing: a driver can reset the GPU channel and leave the call waiting on a fence that never signals. The device layer therefore bounds its waits: a hardware device with no submission completing for 10 seconds is declared lost with reason NoProgress, so the event can come about 10 seconds after the last finished frame. Software adapters (lavapipe and other CPU devices) default to no bound, because a legitimately slow submission there can exceed 10 seconds; set a timeout explicitly to get NoProgress from one. These defaults are the device layer's; the engine does not change them. To change it:
- in code:
new GameOptions { DeviceLostTimeout = TimeSpan.FromSeconds(3) }(orTimeout.InfiniteTimeSpanfor no bound); it applies to a device the engine creates, and a device passed inGameOptions.Devicecarries its ownGpuDeviceOptions.LostTimeout; - from the environment:
ONEGPU_DEVICE_LOST_TIMEOUT=<seconds>(0orinffor no bound), which wins over the option.
Keep it above the longest single GPU job the game submits (a very heavy frame or compute dispatch must not look like a hang).
Limits
- A hang inside the driver's
vkQueuePresentKHRcannot be bounded from outside; only the results the driver returns (device or surface lost) are caught. - Metal has no no-progress timer: a loss there comes from a command-buffer error the system reports.
SimulateDeviceLoss()works on every backend. - A browser's GPU process crash surfaces as a device loss with reason
Reportedand the browser's own text, for exampleA valid external Instance reference no longer exists. Destroying the device (GPUDevice.destroy()) is reasonDestroyed.
Without a handler
A game that does not subscribe to DeviceLost is closed rather than left spinning: the instance asks to quit, and GameApp.Run returns ExitCodes.DeviceLost (6) with error: The graphics device was lost (...) on stderr (or {"ok":false,"error":{"code":"device_lost",...}} with --json). A game that handles the event and then ends the run also gets code 6 from GameApp.Run, so a script can tell a lost device from a normal exit; a handler that keeps the game running leaves the exit code to however the run ends. In a browser, with no handler the frame loop stops and the console says so.
Exit guarantee
A driver that reset its GPU channel can block the thread that closes the window or the device, and even Environment.Exit waits behind it. Seen on an NVIDIA RTX 4070 (Xid 109): the loss was reported after about 10 s, then the process stayed alive for minutes. So GameApp.Run guarantees the end of the process:
- When a run ends in a device loss (with or without a
DeviceLosthandler, in development runs too),GameAppstarts a timer before it closes anything. With no handler the timer starts at the loss itself. - If the process is still alive after
GameApp.DeviceLossExitGrace(default 5 seconds), it flushes what the run printed (the error line, the--jsonresult, the output and error writers given toRun, and the console), waiting at most 2 seconds for that, and then ends the process with the operating system's own exit call, code 6. Nothing else runs: no finalizers, noProcessExithandlers, no saves that were not already written. Save in theDeviceLosthandler, not afterwards. - A handler that keeps the game running is not cut off, and a handler that never ends the run is not covered: the timer starts when the run ends. Browsers have nothing to end (the page keeps running).
GameApp.DeviceLossExitGrace = Timeout.InfiniteTimeSpan(or zero) turns it off. Test hosts that must surviveRun, and programs that callRunagain in the same process, set it to infinite. The timer is armed once per process.OneGame.Platform.ProcessExit.Terminate(code)is the exit call, public for games that run their own watchdog.
Desktop: save, then exit (or start a fresh run)
game.DeviceLost += loss => { game.Storage.Autosave("device lost"); // the world is intact; only drawing is gone game.Platform.RequestQuit(); // GameApp.Run returns ExitCodes.DeviceLost };
The process can also start over inside itself, but only with the exit guarantee off (set GameApp.DeviceLossExitGrace = Timeout.InfiniteTimeSpan before the first run; otherwise the process is ended with code 6 after the grace). Then, when Run returns, call GameApp.Run again. The shared GameHost has dropped the lost device, so the new run creates a new device and window surface (it resumes from game.Storage.LoadLatest() like a fresh start). Anything the game kept that was made from the old device, such as textures it uploaded itself, must be rebuilt; per-instance renderers and atlases are rebuilt by the new instance.
Web: save, then reload the page
A browser cannot rebuild the WebGPU device inside a running page. Saves go to IndexedDB and survive a reload:
game.DeviceLost += loss => { game.Storage.Autosave("device lost"); if (OperatingSystem.IsBrowser()) { BrowserPage.Reload(); // OneGame.Platform; the page starts again and the game resumes from the save } };
On start, game.Storage.LoadLatest() brings the world back.
Control and MCP
Every operation that needs the GPU (capture_frame, capture_sequence, render_graph, pick, project, scene_models, environment, draw_view, shaders, hot_reload) answers {"error":{"code":"device_lost","message":"..."}} at once, on the live server and on a web page's control channel alike, with no timeout and no browser error text. info carries deviceLost (backend, operation, reason, message) once it happened. device_lose (debug builds) makes the device behave as lost, to rehearse the handler; the same hook is GameInstance.SimulateDeviceLoss().
Testing your handler
game.SimulateDeviceLoss() goes through the same path as a real loss. A test can also give a headless instance a fake GpuDevice through GameOptions.Device that throws GpuDeviceLostException. See docs/interfaces/gpu.md for the device's side (IsLost, LostError, Lost, the LostTimeout bound on waits).
Not built: recreating the device, renderers, textures and models in place after a loss.