Repository navigation
fix(wgpu): reset gpu_ready on close + re-init (use-after-free guard) - #427
Conversation
gpu_ready stayed true after closeWindow released the GPU resources (sprite buffers/pipeline → null), so a stray endDrawing/ensureSurface post-close — or a re-init whose initGpu fails — would pass the `if (!gpu_ready)` guard and touch freed handles. Reset it to false in closeWindow (resources freed) and at the top of initWindow (initGpu sets it true on success). gemini High on #426; completes the re-init state hygiene started in #425.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn Changesgpu_ready lifecycle management
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request updates backends/wgpu/src/window.zig to set gpu_ready = false during window initialization and closure to prevent drawing calls on freed handles. The reviewer noted that setting gpu_ready = false at the end of closeWindow() creates a vulnerability where re-entrant events or callbacks could access partially freed resources, and recommended moving this assignment to the beginning of the function.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| // The GPU resources above are released — mark not-ready so a stray | ||
| // `endDrawing`/`ensureSurface` after close (or before a re-init's `initGpu`) | ||
| // hits the `if (!gpu_ready) return` guard instead of touching freed handles. | ||
| gpu_ready = false; |
There was a problem hiding this comment.
Setting gpu_ready = false at the very end of closeWindow() leaves a window of vulnerability. During the release of GPU resources and GLFW termination, callbacks or re-entrant events could be triggered. If these callbacks attempt to draw or update the surface, they will see gpu_ready as true while resources are partially freed, leading to undefined behavior or panics.
It is much safer to set gpu_ready = false at the very beginning of closeWindow() (before releasing any resources) to immediately gate any re-entrant calls. Please move this assignment and its comment to the top of the closeWindow() function.
Addresses the gemini High on #426.
gpu_readystayedtrueaftercloseWindowfreed the GPU resources (sprite buffers/pipeline → null), so a strayendDrawing/ensureSurfaceafter close — or a re-init whoseinitGpufails — would pass theif (!gpu_ready) returnguard and touch freed handles (panic / UB). Reset tofalseincloseWindow(authoritative: resources freed) and at the top ofinitWindow(initGpusets ittrueon success, so a failed re-init stays not-ready). Completes the re-init state hygiene from #425. wgpu example builds (macOS Metal).Summary by CodeRabbit