Bug 261331 - REGRESSION (iPadOS 17 Developer Beta 8): "WebGL: context lost." error when backgrounding Safari
Summary: REGRESSION (iPadOS 17 Developer Beta 8): "WebGL: context lost." error when ba...
Status: RESOLVED DUPLICATE of bug 261313
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: Safari 17
Hardware: iPhone / iPad Other
: P2 Blocker
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2023-09-08 06:53 PDT by Jason Hafer
Modified: 2023-10-08 03:41 PDT (History)
11 users (show)

See Also:


Attachments
error breakpoint (309.43 KB, image/jpeg)
2023-09-25 02:15 PDT, Huabin LING
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Hafer 2023-09-08 06:53:17 PDT
On iOS 17 Developer Beta 8 on tablets only (so iPadOS), we are seeing the error "WebGL: context lost." in the Web Inspector Console, after backgrounding Safari that is viewing a WebGL application.

We are utilizing BabylonJS for a 3D rendering application. In some instances, backgrounding the Safari app, then making it active again in the foreground will cause the WebGL canvas to lose context, essentially crashing WebGL for any browser. Sometimes the crash just forces a full page refresh, and sometimes it hard-crashes with the console error, preventing the canvas element from rendering anything and becoming unresponsive.  Once affected, any tab in Safari or Google Chrome will have unresponsive canvas elements.

We have tested this with BabylonJS, ThreeJS, and minimal vanilla WebGL code, and each fail.  To reproduce the issue, visit any one of the below in Safari:
https://playground.babylonjs.com/
https://threejs.org/playground
https://codepen.io/haferje/pen/QWzdavd
With Web Inspector connected, as the page loads and before the WebGL instance has been initialized, quickly background Safari, then bring it back to the foreground.  In the inspector Console, you will see the context lost error, and in Safari you will see that the webgl scene fails to create.

For our applications, this also happens periodically when we background them even after WebGL is already initialized.
A user on another forum responded to our post saying this happens when locking the device and unlocking again.
This error was not present in beta 7.

We are trying to understand why this is happening, so maybe it can be fixed before iOS 17 is released publicly, or we can create a work-around for the issue.

Thank you.
Comment 1 Radar WebKit Bug Importer 2023-09-08 08:26:39 PDT
<rdar://problem/115173394>
Comment 2 Opher Vishnia 2023-09-11 04:40:25 PDT
We are experiencing the exact same regression issue at eko (where WebGL is used for video post-processing).

To reproduce:
Visit this URL in Safari:
https://play.eko.com/page?id=FaGixErosH

Minimize Safari or lock the phone with the power button. Then unlock the phone - WebGL has stopped, and will not work again on any page (eko or otherwise) with "WebGL: context lost".

Video demo here:
https://drive.google.com/file/d/17Kini4xI-eEg6fOYUpkMfonnIntCepYc/view?usp=sharing
Comment 3 Opher Vishnia 2023-09-11 04:46:16 PDT
Whoops wrong url -
Here is the video demo:

https://drive.google.com/file/d/1ZcVtcxp3RXquWLToCDfPaYb7XaN-xGdg/view?usp=sharing
Comment 4 Huabin LING 2023-09-25 02:00:42 PDT
We are seeing the same issue with Cocos Creator engine, including content in safari web page and content in WKWebView managed by WeChat.
Testing environment:
- iPhone 12
- iOS 16.7 (Lower version is ok)

Testing with our local test case, but it's quite universal, we are testing public pages now
Comment 5 Huabin LING 2023-09-25 02:15:14 PDT
Created attachment 467845 [details]
error breakpoint

The error breakpoint inside WeChat WKWebView is in the screenshot, it indicates `b` from `gl.createShader` is null which is actually due to Context Lost.
We double checked with `ctx.isContextLost()`, it returns true.
Comment 6 Huabin LING 2023-09-25 02:22:18 PDT
Actual behavior in iOS 16.7 Safari

- Opened several webgl site and games, played a little while
- Lock screen
- Unlock screen (The following screen recording is after unlocking)

https://drive.google.com/file/d/1HwSeWnSD0_MnuxrkMR_LoCI0Jgis5HIz/view?usp=sharing
Comment 7 Cheng Runfeng 2023-09-25 05:00:05 PDT
We also encountered this issue on Alipay, with iOS version 16.7 and above. A typical reproduction path is repeatedly entering and exiting a page that uses WebGL. The error message displayed is "WebGL: context lost" or "Error: WebGL unsupported in this browser".
Comment 8 Opher Vishnia 2023-09-25 11:14:42 PDT
In our case after much effort we've been able to narrow this down to a texImage2D call that receives a video element as its 6th argument. If the video is paused, then the WebGl crash happens (and WebGL will no longer be able to get context). If the video is playing, the crash does not happen.

e.g.
texImage2D(
            bindPoint,
            0,
            gl.RGBA,
            gl.RGBA,
            gl.UNSIGNED_BYTE,
            videoElement
        );


Our temporary workaround is to check whether the video was playing or not in iOS 17
Comment 9 Alexey Proskuryakov 2023-09-26 16:29:08 PDT

*** This bug has been marked as a duplicate of bug 261313 ***
Comment 10 Cheng Runfeng 2023-09-26 19:46:59 PDT
(In reply to Alexey Proskuryakov from comment #9)
> 
> *** This bug has been marked as a duplicate of bug 261313 ***

Will this fix be merged into later versions of iOS 16? We‘ve seen that the frequency of occurrence in iOS 16.7 is 20 times that of iOS 17.
Comment 11 Jason Hafer 2023-09-28 08:03:39 PDT
Do we know when this fix is going in?

Is it going to be applied to 17.1?  We are still seeing the same issue in the 17.1 Beta release.
Comment 12 Alexey Proskuryakov 2023-10-04 12:07:43 PDT
Please let us know if this still reproduces in iOS 17.1 Beta 2.

> Will this fix be merged into later versions of iOS 16? We‘ve seen that the frequency of occurrence in iOS 16.7 is 20 times that of iOS 17.

Let me bring this up for discussion.
Comment 13 Ocean 2023-10-08 03:41:43 PDT
We also encountered problems in iOS 16.7. If 17.1 can be fixed, whether there will be a fixed version in iOS 16. After all, there are still many users stuck on this version.