Bug 218305 - WebGL context remains in memory after calling loseContext()
Summary: WebGL context remains in memory after calling loseContext()
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: Safari 14
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
Keywords: InRadar
Depends on:
Reported: 2020-10-28 13:12 PDT by Philip
Modified: 2021-06-13 04:42 PDT (History)
8 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Philip 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')

Example CodePen of dynamically losing & restoring contexts.
Comment 1 Smoley 2020-10-29 18:04:48 PDT
Thanks for filing! Apple Internal see rdar://35920437.
Comment 2 Radar WebKit Bug Importer 2020-10-29 18:35:13 PDT
Comment 3 Philip 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:

PixiJS has a component dedicated to context management:
Comment 4 Yehonatan Daniv 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.