Viewer: exit cleanly after a GPU device loss (SIX-234) #415
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/holdmysocks--SixNG!415
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/415/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@holdmysocks on GitHub · 2026-11-26 21:47 UTC · original
holdmysocks:six-234-device-loss→master· +98 −5 · 4 files · 1 commits · merged 2026-11-26 23:26 UTCFixes SIX-234. After #390, a real device loss still ended in exit code 101. egui-wgpu 0.36.2 panicked on the next paint (renderer.rs:984, "Failed to create staging buffer for index data"), so the red "restart the viewer" line was never drawn.
What changes
Once the device is lost, the viewer shows a native message box ("The GPU device was lost … Restart the viewer.") and exits with code 3.
App::logicandApp::uicheck theGPU_LOSTflag before any 3D view, screenshot orgpu_timeread-back touches the device.uichecks it again after the frame is built and before egui-wgpu paints it.create_buffer_init, or an upload thread. Before the loss, panics behave as they always did.--exit(unattended runs) the message box is skipped: the run logs the reason and exits 3.Why a message box and exit rather than keeping the window alive
eframe gives the app no way to skip egui-wgpu's paint, and every paint needs the lost device: the surface texture plus the vertex and index staging buffers. Keeping the window alive would mean rebuilding the device and every renderer, texture and cache the viewer holds. A message box needs no GPU. Together with the panic hook, it also covers paths the frame-start check can't reach, such as a loss during egui's paint or on another thread. Restarting is what the user has to do either way.
Testing without a driver fault
SIXNG_TEST_GPU_LOSS=Ndestroys the device after N frames. A real fault marks the device invalid and calls the lost callback in one step.destroy()calls the callback only from a later poll, once the queue has drained. So the hook sets the flag first, the way the callback would, then polls so the callback logs its reason. Documented in the README.create_buffer_initpanic from that frame's 3D drawing, which the hook catches. The default panic handler never ran.--exit, the message box showed over the viewer, and pressing OK closed it.cargo test --release -p sixng-gui: 53 passed.cargo check --release --no-default-features -p sixng-gui: clean.All runs on the RTX 4080.
After a device loss egui-wgpu panicked on the next paint ("Failed to create staging buffer"), so the viewer exited with 101 before the red restart line from #390 was drawn. eframe has no way to skip a paint, so once the device is lost the viewer now shows a native message box (no GPU needed) and exits with code 3: - App::logic and App::ui check the flag before any 3D view, screenshot or frame timer touches the device, and again after the frame is built, before egui-wgpu paints it. - A panic hook turns any panic after the loss (egui-wgpu, a wgpu helper, an upload thread) into the same clean exit. - The Map 3D model and cell upload threads stop once the flag is set. - SIXNG_TEST_GPU_LOSS=N destroys the device after N frames, for testing. `--exit` skips the box for unattended runs.