Bug 229706

Summary: REGRESSION (Safari 14): webgl_loader_texture_basis three.js example sometimes fails
Product: WebKit Reporter: Michael Herzog <michael.herzog>
Component: WebKit2Assignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: achristensen, ap, blascoburguillos, cdumez, dino, kkinnunen, sabouhallawa, simon.fraser, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: iPhone / iPad   
OS: iOS 14   

Description Michael Herzog 2021-08-31 03:24:43 PDT
The following example pages decodes a texture in a web worker, transfers the result into the main thread via "postMessage()" and then renders the result on a plane.

https://threejs.org/examples/webgl_loader_texture_basis

Expected behavior: The texture is always rendered correctly.

Actual behavior: Sometimes the plane is white since no texture is applied. This only happens sporadicly (maybe one out of ten reloads).

A user at GitHub found out that the root cause of this issue is a missing message from the worker. Meaning the worker sends the message but it never reaches the main thread.

https://github.com/mrdoob/three.js/issues/19717#issuecomment-653581829

This issue only happens in WebKit based browsers on iOS, iPadOS and macOS.

According to the comments at GitHub the example used to work consistently in earlier version of Safari (meaning < 14).
Comment 1 Chris Dumez 2021-09-03 13:19:47 PDT
Thank you for the bug report and the test site. It looks like I can I am able to reproduce on Safari 15 on macOS.
Comment 2 Chris Dumez 2021-09-03 13:39:37 PDT
Hmm, I see the page sending 2 messages to the worker and us dispatching those 2 message events on the WorkerGlobalScope. However, I do not see any messages being sent *from* the worker (no WorkerGlobalScope.postMessage() or MessagePort.postMessage() calls).
Comment 3 Chris Dumez 2021-09-03 14:39:52 PDT
I don't think this is an issue with postMessage(). The worker simply doesn't call postMessage() to send back the results, even though it received 2 messages from the main thread. 

So presumably, whatever operation is happening between the worker receiving the messages and the worker calling postMessage() with the results is getting stuck, sometimes.
Comment 4 Chris Dumez 2021-09-03 15:02:11 PDT
Since canvas is involved, I tried disabling the GPU process but it didn't help.
Comment 5 Michael Herzog 2021-09-05 01:08:35 PDT
The worker definitely calls "postMessage()" at this place: https://github.com/mrdoob/three.js/blob/105bd07ffce14f8f8982417e16b99c0d066ce3f1/examples/jsm/loaders/BasisTextureLoader.js#L418

Interestingly, when I add a console.log() right before this line, you see a console log when the demo works. However, when the plane keeps white (so when the issue appears), there is no log in the console.
Comment 6 Alexey Proskuryakov 2021-09-05 14:59:12 PDT
Re-titling to say what we know about the issue, as it's been demonstrated to NOT be related to postMessage(), given that the execution doesn't even reach postMessage() in the worker.
Comment 7 Radar WebKit Bug Importer 2021-09-07 03:25:17 PDT
<rdar://problem/82814418>
Comment 8 blascoburguillos 2021-10-27 00:46:32 PDT
I´m also experiencing this issue. Any news or updates?