Force WebGL context loss on Canvas cleanup to prevent GPU leaks - #946
Draft
posthog[bot] wants to merge 1 commit into
Draft
Force WebGL context loss on Canvas cleanup to prevent GPU leaks#946posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
The main render Canvas called renderer.dispose() on teardown but never renderer.forceContextLoss(), so each unmount leaked its WebGL context. Once enough live contexts pile up, the browser force-loses the oldest, three.js then calls createShader() on the dead context, gets null, and throws in shaderSource(). Mirrors the fix already applied to OrientationCubeCanvas in #673. Also splits the single effect so the renderer is created once and only the camera is rebuilt on camera-type changes, instead of tearing down and recreating the whole renderer (and its context) on every switch. Generated-By: PostHog Code Task-Id: 5ccbf1fc-0307-4461-9b52-9ff34cf8bfae
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The main render
Canvas.tsxcallsrenderer.dispose()on teardown but neverrenderer.forceContextLoss(), so each unmount leaked its WebGL context. Once enough live contexts accumulate, the browser silently force-loses the oldest one; three.js then callsgl.createShader()on the dead context, gets backnull, and throws:This mirrors the fix already applied to the sibling
OrientationCubeCanvas.tsxin #673.The change also splits the single mount effect in two: the renderer is now created once and reused, while only the camera is rebuilt when
cameraTypechanges. Previously every camera-type switch tore down and recreated the whole renderer (and its GPU context), churning through contexts unnecessarily. The active camera lives in a ref so the animation/resize loops always read the current one.Why
A user hit a WebGL context-loss crash in the 3D viewer. The root cause is the leaked GPU contexts on unmount, which compound for anyone who opens or switches between many viewers in a session.
Test plan
npx tsc --noEmitpassesnpm run buildsucceedsCreated with PostHog Code from an inbox report.