<?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>289601</bug_id>
          
          <creation_ts>2025-03-12 02:16:59 -0700</creation_ts>
          <short_desc>WebGL context suddenly lost on buffers upload (iOS 18)</short_desc>
          <delta_ts>2025-03-28 06:46:37 -0700</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>WebKit Nightly Build</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 18</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>286297</dup_id>
          
          <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="Kimmo Kinnunen">kkinnunen</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>djg</cc>
    
    <cc>filipp</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>robyer1</cc>
    
    <cc>rohan</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2102492</commentid>
    <comment_count>0</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2025-03-12 02:16:59 -0700</bug_when>
    <thetext>I have similar issue with pure WebGL2 API (ThreeJS) on same devices, iOS 18
Context suddenly lost on buffers upload. Context can not be created after page reload, requires browser kill-restart.
Can create a minimal example to reproduce, if needed

Here is a zip to reproduce, open index.html with iOS safari
console shows &quot;context lost&quot;
webgl context can not be created until browser killed
https://drive.google.com/file/d/11DlSrLWyvUI4gAmZk8duuzD1HHmgQN4S/view?usp=sharing


From bug 286297</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2102493</commentid>
    <comment_count>1</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2025-03-12 02:19:54 -0700</bug_when>
    <thetext>Original Reporter, could you provide the exact devices you are seeing the problem?

I cannot repro immediately with iPhone 12 Pro

I do see errors in the console:
[Error] Failed to load resource: the server responded with a status of 404 (File not found) (e9140837.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (File not found) (index.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (File not found) (index.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (File not found) (92ea56b3.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (File not found) (f7b937b1.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (File not found) (fabf3b3d.js.map, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (File not found) (TrimbimWorker.js.map, line 0)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2104331</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-03-19 07:33:36 -0700</bug_when>
    <thetext>&lt;rdar://problem/147409007&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2105851</commentid>
    <comment_count>3</comment_count>
    <who name="">rohan</who>
    <bug_when>2025-03-25 05:21:38 -0700</bug_when>
    <thetext>I have been facing the issue with my app on following devices I have access to - 

M4 iPads (Air and Pro) (iOS 18.3.2)
M3 Max Macbook Pro 16&quot; (MacOS 15.3.1)

Issue is not present on my iPhone 12 Pro (iOS 18.3.2) as well as intel/M1/M2/M3 iPads.

May be present in other devices apart from these. Minimum version of my app displaying the diamonds eyewear frame can be found on https://3d.sprie.io/dita_diamonds/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2105853</commentid>
    <comment_count>4</comment_count>
    <who name="">rohan</who>
    <bug_when>2025-03-25 05:31:56 -0700</bug_when>
    <thetext>The results are same as the OP has reported. WebGL context lost. Once this occurs, all other WebGL apps stop working. The ones that have been already loaded in other tabs before this error will also break when coming to foreground. New app instance starts with WebGL context lost. Safari needs hard restart to resolve these.
Sometimes entire Safari session becomes corrupted, regardless of whether it has any WebGL components. Sometimes MacBook completely freezes and needs hard restart.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106478</commentid>
    <comment_count>5</comment_count>
    <who name="">robyer1</who>
    <bug_when>2025-03-27 09:59:45 -0700</bug_when>
    <thetext>I am also finding this issue reproducible in both Safari and also Safari Webview in Flutter InAppWebView on an iPad Pro 6th generation Safari, iPhone 13 mini Safari, Mac Mini M1 MacOS Safari using the following test website built on ThreeJS if you use the red buttons at the top to directly navigate between the two 3D pages, sometimes the context is lost or on dispose of the WebGL context, the new webpage loading can get stuck in a loop of reloading or load a blank page or crash safari.

https://demo.epm.agency/safarikiller2/threejs/main/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106775</commentid>
    <comment_count>6</comment_count>
    <who name="">robyer1</who>
    <bug_when>2025-03-28 04:17:27 -0700</bug_when>
    <thetext>Here is a video recorded on the iPad Pro demonstrating what happens when I am switching between the 3d webpages a few times before it white screens and crashes. The same behaviour is observed in Webview on iOS.

https://drive.google.com/file/d/1685t3NQEHJQuFPPvKZyuxG6yt-YqPX-u/view?usp=sharing</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106786</commentid>
    <comment_count>7</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2025-03-28 05:38:10 -0700</bug_when>
    <thetext>
&gt; https://demo.epm.agency/safarikiller2/threejs/main/

Thanks for the report. This page uses 2.7gb of memory when loaded on desktop. If that&apos;s same amount on iPad, the context is lost due to running out of memory.

If there&apos;s more to this, feel free to comment or open a new specific bug. The more specific you can be and the smaller the reproduction case, the easier it is to fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106788</commentid>
    <comment_count>8</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2025-03-28 05:51:01 -0700</bug_when>
    <thetext>&gt; https://3d.sprie.io/dita_diamonds/
Tracking this in bug 290620</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106793</commentid>
    <comment_count>9</comment_count>
    <who name="">robyer1</who>
    <bug_when>2025-03-28 05:56:52 -0700</bug_when>
    <thetext>(In reply to Kimmo Kinnunen from comment #7)
&gt; 
&gt; &gt; https://demo.epm.agency/safarikiller2/threejs/main/
&gt; 
&gt; Thanks for the report. This page uses 2.7gb of memory when loaded on
&gt; desktop. If that&apos;s same amount on iPad, the context is lost due to running
&gt; out of memory.
&gt; 
&gt; If there&apos;s more to this, feel free to comment or open a new specific bug.
&gt; The more specific you can be and the smaller the reproduction case, the
&gt; easier it is to fix.

Here is a smaller repro page, I have many websites that this issue happens with only when on Safari on iOS. Webview on iOS and Safari on MacOS on all my devices:

iPhone 13 mini
iPad Pro 2020
Mac Mini M1

https://demo.epm.agency/epmpitest/index.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106795</commentid>
    <comment_count>10</comment_count>
    <who name="">robyer1</who>
    <bug_when>2025-03-28 06:03:08 -0700</bug_when>
    <thetext>*Click the hotspots in the sample above to move to the next page, then use the red button at the top to go back to the main page</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106799</commentid>
    <comment_count>11</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2025-03-28 06:07:55 -0700</bug_when>
    <thetext>&gt; https://demo.epm.agency/epmpitest/index.html
Thanks, tracking this in bug  290623</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106800</commentid>
    <comment_count>12</comment_count>
    <who name="Filipp Keks">filipp</who>
    <bug_when>2025-03-28 06:10:58 -0700</bug_when>
    <thetext>I can reproduce safari crash with with example https://drive.google.com/file/d/11DlSrLWyvUI4gAmZk8duuzD1HHmgQN4S/view?usp=sharing
iPad Pro (12.9-inch) (4th generation)
Model number: MY2H2HC/A
iPadOS: 18.3.1

after some trial and error, i found out, that this glsl vertex shader line is triggering crash
flat varying vec3 flatNormal;

crash happens even if flatNormal value is unused
probability of crash increases with increase of amount of vertices
when amount of vertices go above ~30000 crash is almost 100%
removing &quot;flat&quot; directive, makes issue disappear completely</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106804</commentid>
    <comment_count>13</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2025-03-28 06:24:48 -0700</bug_when>
    <thetext>&gt;crash happens even if flatNormal value is unused

Thanks for confirming. I can repro that this is the same bug as bug 286297.

If the provoking vertex doesn&apos;t matter for the renddering, https://registry.khronos.org/webgl/extensions/WEBGL_provoking_vertex/ should be used to ensure good perf on Apple and perhaps Windows devices.

*** This bug has been marked as a duplicate of bug 286297 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106806</commentid>
    <comment_count>14</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2025-03-28 06:26:31 -0700</bug_when>
    <thetext>And to add:
The use of WEBGL_provoking_vertex should also solve the context loss.

E.g. add:
const epv = gl.getExtension(&apos;WEBGL_provoking_vertex&apos;);
      if (epv) {
        epv.provokingVertexWEBGL(epv.FIRST_VERTEX_CONVENTION_WEBGL);
      }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2106807</commentid>
    <comment_count>15</comment_count>
    <who name="Filipp Keks">filipp</who>
    <bug_when>2025-03-28 06:46:37 -0700</bug_when>
    <thetext>enabling FIRST_VERTEX_CONVENTION_WEBGL using WEBGL_provoking_vertex extension, fixed the crash
thanx for the tip!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>