<?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>274300</bug_id>
          
          <creation_ts>2024-05-16 23:54:00 -0700</creation_ts>
          <short_desc>render not work in offscreencanvas in some case</short_desc>
          <delta_ts>2024-05-16 23:59:33 -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>Canvas</component>
          <version>Safari 17</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>274301</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="skyler">iskyler1993</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dino</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2035960</commentid>
    <comment_count>0</comment_count>
    <who name="skyler">iskyler1993</who>
    <bug_when>2024-05-16 23:54:00 -0700</bug_when>
    <thetext>we have found a case that rendering in offscreencanvas not work on both mac safari and iOS safari (17.4.1)

Use Cases:
1. create work0, pass the offscreencanvas to it
2. work0 post the offscreencanvas back to main thread
3. main thread create worker1 and pass the offscreencanvas to it
4. use raf in worker1

and we found that if we make the handler in step 3(named SpawnThread) to execute in setTimeout, rendering would be ok

not sure if it&apos;s a bug, but the case work on chrome

the sample code below 

test.html
```
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
    &lt;title&gt;Document&lt;/title&gt;
  &lt;/head&gt;

  &lt;body&gt;
    &lt;canvas id=&quot;canvas&quot;&gt;&lt;/canvas&gt;
  &lt;/body&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var canvas = document.getElementById(&quot;canvas&quot;);

    var Module = (window.Module = {});
    var workerJs = &quot;./test.worker.js&quot;;

    var worker0 = new Worker(workerJs);

    function spawnThread(data) {
      var worker = new Worker(workerJs);
      worker.postMessage({
        type: &quot;load&quot;,
      });
      worker.postMessage(
        {
          type: &quot;run1&quot;,
          canvas: data.canvas,
        },
        [data.canvas]
      );
    }
    
    worker0.onmessage = function (event) {
      if (event.data.type === &quot;loaded&quot;) {
        console.log(&quot;main thread receive worker0 loaded&quot;);
      } else if (event.data.type === &quot;spawnThread&quot;) {
        console.log(&quot;spawnThread&quot;); 
        // setTimeout(spawnThread, 0, event.data);
        spawnThread(event.data);
      }
    };

    worker0.postMessage({
      type: &quot;load&quot;,
    });
    var offscreencanvas = canvas.transferControlToOffscreen();
    worker0.postMessage(
      {
        type: &quot;run0&quot;,
        canvas: offscreencanvas,
      },
      [offscreencanvas]
    );

  &lt;/script&gt;
&lt;/html&gt;
```

test.worker.js
```
var gl;
var initGL = function (data) {
  var canvas = data.canvas;
  gl = canvas.getContext(&quot;webgl&quot;);
  if (!gl) {
    console.error(&quot;Failed to get the rendering context for WebGL&quot;);
    return;
  }
};
var r = 0.01;
var renderLoop = function () {
  console.log(&quot;start renderLoop&quot;);
  function renderFunc() {
    if (r &gt; 1) {
      r = 0.01;
    }
    r += 0.01;
    gl.clearColor(r, 0, 0, 1);
    gl.clear(gl.COLOR_BUFFER_BIT);
    requestAnimationFrame(renderFunc);
  }

  requestAnimationFrame(renderFunc);
};

self.onmessage = function (event) {
  if (event.data.type === &quot;load&quot;) {
    console.log(&quot;worker onload&quot;);
  } else if (event.data.type === &quot;run0&quot;) {
    console.log(&quot;worker on run0&quot;);
    postMessage(
      {
        type: &quot;spawnThread&quot;,
        canvas: event.data.canvas,
      },
      [event.data.canvas]
    );
  } else if (event.data.type === &quot;run1&quot;) {
    console.log(&quot;worker on run1&quot;);
    initGL(event.data);
    renderLoop();
  }
};

```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035962</commentid>
    <comment_count>1</comment_count>
    <who name="skyler">iskyler1993</who>
    <bug_when>2024-05-16 23:59:33 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 274301 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>