[WebGL] avoid 'forceContextLost' notifications during destruction#1588
Conversation
GraphicsContextGLANGLE::reshape(0, 0) may trigger `forceContextLost` if it fails to reshape FBOs. If it happens during HTMLCanvasElement destruction it will capture areference to an HTMLCanvasElement that is being destroyed, and lead to a double destruction of HTMLCanvasElement and random crashes.
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash during HTMLCanvasElement destruction where reshape(0,0) could trigger context loss notifications that capture a reference to the element being destroyed, leading to double destruction and crashes.
- Reorders operations in
destroyGraphicsContextGL()to set client to nullptr before calling reshape - Prevents
forceContextLostcallbacks during destruction that would queue tasks with references to the destructing canvas element
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
attaching a simple test page where the browser is crashing because of "pure" function call during the destruction of 2d canvas context: webgl_test.html callstack |
|
This is a problem just I've just discovered on 2.38 while working on the page lifecycle freeze (despite it doesn't lead to a crash there). But I fixed it on 2.38 by reshaping to (1, 1) instead of (0, 0), so we can still have the early release of resources. I think we could do the same here. |
reshaping to (1,1) doesn't solve the underlying issue. It can still fail for some reason and call forceLostContext() on a canvas object that is being destroyed (and capture a reference to it), resulting in a crash. |
What a pity. Seems that the reshape is causing some trouble on 2.46 with ANGLE that doesn't happen on 2.38 without it. Ok, let's remove it then. |
GraphicsContextGLANGLE::reshape(0, 0) may trigger
forceContextLostif it fails to reshape FBOs. If it happens during HTMLCanvasElement destruction, it will capture a reference to an HTMLCanvasElement that is being destroyed, and lead to a double destruction of HTMLCanvasElement and random crashes.Here is callstack showing how forceLostContext captures a reference to HTMLCanvasElement during destruction: