Restore on webgl context loss#3968
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughRefactors GameView for nullable/lazy renderer and adds a ChangesWebGL Context Recovery
Sequence DiagramsequenceDiagram
participant WebGL as WebGL Context
participant GameView
participant GPURenderer
participant Client as ClientGameRunner
participant FrameBuilder as WebGLFrameBuilder
WebGL->>GameView: contextlost
GameView->>GPURenderer: dispose() / set renderer = null
GameView->>Client: emit "contextrestored"
Client->>FrameBuilder: clearCaches()
Client->>FrameBuilder: regenerate terrain refs/bytes & reupload frameData (tiles/trails/units)
FrameBuilder->>GameView: update(gameView)
GameView->>GPURenderer: initRenderer() (lazy)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/client/render/gl/GameView.ts`:
- Around line 255-256: The updatePalette method currently only calls
this.renderer.updatePalette(paletteData) and neglects to update the cached
palette used during restore; modify updatePalette (in class GameView) to also
store a copy of the incoming palette into this.paletteData (e.g.,
this.paletteData = new Float32Array(paletteData) or similar) so the
restore/rebuild path uses the runtime-updated palette; keep the existing
renderer.updatePalette call intact.
- Around line 74-105: The new GPURenderer is created with a default camera after
a context loss because we never save/reapply the previous camera; modify the
class to capture the current camera into a cachedCameraState before disposing
(in onContextLost — call renderer.getCameraState() or read renderer.camera) and
then, inside initRenderer (or immediately after creating the new GPURenderer),
reapply that state via renderer.setCameraState(cachedCameraState) (or assign
renderer.camera = cachedCameraState) so the view is restored; ensure
onContextRestored still calls initRenderer and that cachedCameraState is
cleared/validated as needed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 07c6744a-4b13-4e52-aeeb-066be4871586
📒 Files selected for processing (5)
src/client/ClientGameRunner.tssrc/client/WebGLFrameBuilder.tssrc/client/render/gl/Events.tssrc/client/render/gl/GameView.tssrc/client/render/gl/passes/TerritoryPass.ts
Description:
When WebGL context is lost, restore context and all elements.
In GameView, handle potentially transient undefined states during context loss gracefully.
Test with chrome://gpucrash from another tab, then return to the game tab to see it being restored.
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
tryout33