WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
218305
WebGL context remains in memory after calling loseContext()
https://bugs.webkit.org/show_bug.cgi?id=218305
Summary
WebGL context remains in memory after calling loseContext()
Philip
Reported
2020-10-28 13:12:46 PDT
To reproduce: Create over 16 WebGL contexts and call loseContext on each. On the 17th call two errors will be thrown:
> ‘There are too many active WebGL contexts on this page, the oldest context will be lost.’ > ‘WebGL: INVALID_OPERATION: loseContext: context already lost’
It's expected that these contexts would not remain in memory. Code snippet: for (let i = 0; i < 17; i++) { const canvas = document.createElement('canvas'); const gl = canvas.getContext('webgl'); const extension = gl.getExtension('WEBGL_lose_context') extension.loseContext(); } Example CodePen of dynamically losing & restoring contexts.
https://codepen.io/philipbell/pen/RwRQGmo
Attachments
Add attachment
proposed patch, testcase, etc.
Smoley
Comment 1
2020-10-29 18:04:48 PDT
Thanks for filing! Apple Internal see
rdar://35920437
.
Radar WebKit Bug Importer
Comment 2
2020-10-29 18:35:13 PDT
<
rdar://problem/70838378
>
Philip
Comment 3
2020-11-03 10:25:41 PST
Some additional context: loseContext is used in popular WebGL libraries including Three.js and PixiJS. Without this method their context management code fails. Three.js manages context directly in the renderer code:
https://github.com/mrdoob/three.js/blob/3989bb4a00a9f38b1df5dc02bcbc1e5a1b80df53/src/renderers/WebGLRenderer.js#L345-L357
PixiJS has a component dedicated to context management:
https://github.com/pixijs/pixi.js/blob/9ff49a23670bdb0ed864d4e53fb91d524eab59f2/packages/core/src/context/ContextSystem.ts#L248-L262
Yehonatan Daniv
Comment 4
2021-05-24 05:46:05 PDT
Looks like a duplicate of this:
https://bugs.webkit.org/show_bug.cgi?id=200031
At Wix we use Kampos (
https://github.com/wix/kampos
), which doesn't use the WEBGL_lose_context plugin, but still getting the same error.
Alex Suzuki
Comment 5
2026-02-26 05:34:40 PST
I do not think this is related to
https://bugs.webkit.org/show_bug.cgi?id=200031
, which is marked as FIXED. It still reproduces for me on iOS 26.3, although I don't understand if it's just a misleading error message or an actual error. I ran into this when benchmarking a barcode scanning library the uses WebGL to pre-process camera frames: basically a long loop that in every iteration created and released infrastructure that owns an OffscreenCanvas and WebGL context. I experienced crashes too, but those disappeared when each iteration was put into a separate turn of the event loop (i.e. each iteration wrapped in a setTimeout() invocation). Separate reproducer (before I found this issue):
https://github.com/pixelverse-llc/ios-safari-webgl-context-not-released
GitHub pages site:
https://pixelverse-llc.github.io/ios-safari-webgl-context-not-released/
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug