<?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>250307</bug_id>
          
          <creation_ts>2023-01-08 21:01:07 -0800</creation_ts>
          <short_desc>&quot;TypeError: Type error&quot; when calling WebGL bufferData with typed array backed by growable SharedArrayBuffer</short_desc>
          <delta_ts>2023-01-09 15:33:43 -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 Technology Preview</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 13</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>249635</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=248024</see_also>
          <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>
          <dependson>248024</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ian Kettlewell">Ian.kettlewell</reporter>
          <assigned_to name="Yusuke Suzuki">ysuzuki</assigned_to>
          <cc>dino</cc>
    
    <cc>kbr</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1923987</commentid>
    <comment_count>0</comment_count>
      <attachid>464415</attachid>
    <who name="Ian Kettlewell">Ian.kettlewell</who>
    <bug_when>2023-01-08 21:01:07 -0800</bug_when>
    <thetext>Created attachment 464415
Index.html file with the code to reproduce the issue

As title says. The following code errors in Safari Technical Preview 160:

```
 let gl =
            canvas.getContext(&apos;webgl2&apos;);


        const sab = new SharedArrayBuffer(1024, {
            maxByteLength: 2048 // This is important, without it the page runs fine
        });

        const data = new Uint8Array(sab, 0, 32);
        let buffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, buffer); // TypeError: Type error
        gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
```

I discovered this in a game jam entry I made (https://ianjk.com/ld52/) that I was testing in the Safari Technology Preview. For some reason the SharedArrayBuffer backing the WebAssembly binary is automatically made &apos;growable&apos; in Safari Technology Preview 160. In Safari 16.2 that does not happen so both the attached example and my game jam entry run fine.

I&apos;m not versed in where to file WebKit bugs so I&apos;ve filed this under &apos;WebGL&apos;, but please reclassify if there&apos;s a more appropriate &apos;Component&apos;. :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1924007</commentid>
    <comment_count>1</comment_count>
      <attachid>464416</attachid>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2023-01-09 01:43:46 -0800</bug_when>
    <thetext>Created attachment 464416
server to run the file with</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1924008</commentid>
    <comment_count>2</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2023-01-09 01:45:23 -0800</bug_when>
    <thetext>Likely regressed with bug 248024

Yusuke, it appears intentional.
Is there anything WebGL code can do to opt into using the growable array buffers?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1924009</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-01-09 01:45:34 -0800</bug_when>
    <thetext>&lt;rdar://problem/104022514&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1924066</commentid>
    <comment_count>4</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2023-01-09 06:00:18 -0800</bug_when>
    <thetext>(In reply to Kimmo Kinnunen from comment #2)
&gt; Likely regressed with bug 248024
&gt; 
&gt; Yusuke, it appears intentional.
&gt; Is there anything WebGL code can do to opt into using the growable array
&gt; buffers?

Growable SharedArrayBuffer / Resizable ArrayBuffer cannot be used for IDL saying ArrayBuffer without [[AllowResizable]] annotation. (This is explicitly specified for resizable array-buffer / growable shared-array-buffer).

https://webidl.spec.whatwg.org/#AllowResizable

&quot;If the [AllowResizable] extended attribute and the [AllowShared] extended attribute both appear on one of the buffer source types, it creates a new IDL type that allows the buffer source type to be additionally backed by an ECMAScript SharedArrayBuffer that is growable.&quot;

Thus, given that WebGL IDL is not saying [[AllowResizable]], I think this behavior is expected. (bufferData does not have [[AllowResizable]]).

On the other hand,

&gt; I discovered this in a game jam entry I made (https://ianjk.com/ld52/) that I was testing in the Safari Technology Preview. For some reason the SharedArrayBuffer backing the WebAssembly binary is automatically made &apos;growable&apos; in Safari Technology Preview 160. In Safari 16.2 that does not happen so both the attached example and my game jam entry run fine.


This is fixed in bug 249635.

*** This bug has been marked as a duplicate of bug 249635 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1924188</commentid>
    <comment_count>5</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2023-01-09 15:33:43 -0800</bug_when>
    <thetext>For what it&apos;s worth I think the WebGL IDL should be updated to add [AllowResizable] for compatibility with WebAssembly applications that use resizable memory. Have filed https://github.com/KhronosGroup/WebGL/issues/3510 about this.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>464415</attachid>
            <date>2023-01-08 21:01:07 -0800</date>
            <delta_ts>2023-01-08 21:01:07 -0800</delta_ts>
            <desc>Index.html file with the code to reproduce the issue</desc>
            <filename>index.html</filename>
            <type>text/html</type>
            <size>523</size>
            <attacher name="Ian Kettlewell">Ian.kettlewell</attacher>
            
              <data encoding="base64">PGh0bWw+CjxoMT5IZWxsbzwvaDE+CjxjYW52YXMgaWQ9ImNhbnZhcyI+PC9jYW52YXM+Cgo8Ym9k
eT4KICAgIDxzY3JpcHQ+CiAgICAgICAgY2FudmFzID0gZG9jdW1lbnQKICAgICAgICAgICAgLmdl
dEVsZW1lbnRCeUlkKCJjYW52YXMiKTsKICAgICAgICBsZXQgZ2wgPQogICAgICAgICAgICBjYW52
YXMuZ2V0Q29udGV4dCgnd2ViZ2wyJyk7CgoKICAgICAgICBjb25zdCBzYWIgPSBuZXcgU2hhcmVk
QXJyYXlCdWZmZXIoMTAyNCwgewogICAgICAgICAgICBtYXhCeXRlTGVuZ3RoOiAyMDQ4CiAgICAg
ICAgfSk7CgogICAgICAgIGNvbnN0IGRhdGEgPSBuZXcgVWludDhBcnJheShzYWIsIDAsIDMyKTsK
ICAgICAgICBsZXQgYnVmZmVyID0gZ2wuY3JlYXRlQnVmZmVyKCk7CiAgICAgICAgZ2wuYmluZEJ1
ZmZlcihnbC5BUlJBWV9CVUZGRVIsIGJ1ZmZlcik7CiAgICAgICAgZ2wuYnVmZmVyRGF0YShnbC5B
UlJBWV9CVUZGRVIsIGRhdGEsIGdsLlNUQVRJQ19EUkFXKTsKCiAgICA8L3NjcmlwdD4KPC9ib2R5
PgoKPC9odG1sPg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>464416</attachid>
            <date>2023-01-09 01:43:46 -0800</date>
            <delta_ts>2023-01-09 01:43:46 -0800</delta_ts>
            <desc>server to run the file with</desc>
            <filename>http-server-same-origin.py</filename>
            <type>text/x-python-script</type>
            <size>415</size>
            <attacher name="Kimmo Kinnunen">kkinnunen</attacher>
            
              <data encoding="base64">IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCmZyb20gaHR0cCBpbXBvcnQgc2VydmVyCgpjbGFzcyBNeUhU
VFBSZXF1ZXN0SGFuZGxlcihzZXJ2ZXIuU2ltcGxlSFRUUFJlcXVlc3RIYW5kbGVyKToKICAgIGRl
ZiBlbmRfaGVhZGVycyhzZWxmKToKICAgICAgICBzZWxmLnNlbmRfaGVhZGVyKCJDcm9zcy1Pcmln
aW4tT3BlbmVyLVBvbGljeSIsICJzYW1lLW9yaWdpbiIpCiAgICAgICAgc2VsZi5zZW5kX2hlYWRl
cigiQ3Jvc3MtT3JpZ2luLUVtYmVkZGVyLVBvbGljeSIsICJyZXF1aXJlLWNvcnAiKQogICAgICAg
IHNlcnZlci5TaW1wbGVIVFRQUmVxdWVzdEhhbmRsZXIuZW5kX2hlYWRlcnMoc2VsZikKCmlmIF9f
bmFtZV9fID09ICdfX21haW5fXyc6CiAgICBzZXJ2ZXIudGVzdChIYW5kbGVyQ2xhc3M9TXlIVFRQ
UmVxdWVzdEhhbmRsZXIpCg==
</data>

          </attachment>
      

    </bug>

</bugzilla>