<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>218305</bug_id>
          
          <creation_ts>2020-10-28 13:12:46 -0700</creation_ts>
          <short_desc>WebGL context remains in memory after calling loseContext()</short_desc>
          <delta_ts>2026-02-26 05:34:40 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebGL</component>
          <version>Safari 14</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Philip">philipbell</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>alex</cc>
    
    <cc>dino</cc>
    
    <cc>jdarpinian</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>maggotfish</cc>
    
    <cc>noam</cc>
    
    <cc>smoley</cc>
    
    <cc>takashi.th.hasegawa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1702467</commentid>
    <comment_count>0</comment_count>
    <who name="Philip">philipbell</who>
    <bug_when>2020-10-28 13:12:46 -0700</bug_when>
    <thetext>To reproduce: 
Create over 16 WebGL contexts and call loseContext on each.
On the 17th call two errors will be thrown: 
&gt; ‘There are too many active WebGL contexts on this page, the oldest context will be lost.’
&gt; ‘WebGL: INVALID_OPERATION: loseContext: context already lost’
It&apos;s expected that these contexts would not remain in memory.

Code snippet:
for (let i = 0; i &lt; 17; i++) {
  const canvas = document.createElement(&apos;canvas&apos;);
  const gl = canvas.getContext(&apos;webgl&apos;);  
  const extension = gl.getExtension(&apos;WEBGL_lose_context&apos;)
  extension.loseContext();
}

Example CodePen of dynamically losing &amp; restoring contexts.
https://codepen.io/philipbell/pen/RwRQGmo</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702935</commentid>
    <comment_count>1</comment_count>
    <who name="Smoley">smoley</who>
    <bug_when>2020-10-29 18:04:48 -0700</bug_when>
    <thetext>Thanks for filing! Apple Internal see rdar://35920437.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1702943</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-10-29 18:35:13 -0700</bug_when>
    <thetext>&lt;rdar://problem/70838378&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1704062</commentid>
    <comment_count>3</comment_count>
    <who name="Philip">philipbell</who>
    <bug_when>2020-11-03 10:25:41 -0800</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1763101</commentid>
    <comment_count>4</comment_count>
    <who name="Yehonatan Daniv">maggotfish</who>
    <bug_when>2021-05-24 05:46:05 -0700</bug_when>
    <thetext>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&apos;t use the WEBGL_lose_context plugin, but still getting the same error.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2185200</commentid>
    <comment_count>5</comment_count>
    <who name="Alex Suzuki">alex</who>
    <bug_when>2026-02-26 05:34:40 -0800</bug_when>
    <thetext>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&apos;t understand if it&apos;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/</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>