Skip to content

JS exception/crash in emsdk 6.0.2 when calling UTF8ToString #27241

Closed

Description

@floooh

Please include the following in your bug report:

Version of emscripten/emsdk:
6.0.2

Description

I'm getting a 'crash' in 6.0.2 inside UTF8toString called from _emscripten_glShaderSource (this is a regression in 6.0.2 which didn't happen in 6.0.1):

Uncaught TypeError: Failed to execute 'decode' on 'TextDecoder': The provided ArrayBuffer value must not be resizable
    at UTF8ArrayToString (v6502r.js:919:28)
    at UTF8ToString (v6502r.js:964:20)
    at Object.getSource (v6502r.js:2366:21)
    at _emscripten_glShaderSource (v6502r.js:3607:23)
    at v6502r.wasm._sg_gl_compile_shader (v6502r.wasm:0x6caca)
    at v6502r.wasm._sg_gl_create_shader (v6502r.wasm:0x6c17c)
    at v6502r.wasm._sg_create_shader (v6502r.wasm:0x3ff32)
    at v6502r.wasm._sg_init_shader (v6502r.wasm:0x3e30a)
    at v6502r.wasm.sg_make_shader (v6502r.wasm:0x4413a)
    at v6502r.wasm.simgui_setup (v6502r.wasm:0x50794)

The code around the bottom of the callstack is:

  var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
  
      var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
  
      // When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.
      if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
        // ========> CRASH HAPPENS HERE
        return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
      }
      var str = '';

...the crash happens on the first call to UTF8Decoder.decode(), there are plenty of earlier calls to UTF8ArrayToString(), but those all skip the if() condition (I guess this is why the problem didn't show up during testing, assuming the if-body isn't covered by tests).

...I guess this is related to this change in 6.0.2:

The GROWABLE_ARRAYBUFFERS setting now defaults to 1, which means it will be used when available. Note that this only affects programs that are built with ALLOW_MEMORY_GROWTH, which is not enabled by default. (#27212)

PS: cc @sbc100, and also link to Discord message I wrote: https://discord.com/channels/453584038356058112/590215642444202044/1522227441165275307

Activity

  1. added theissue type on Jul 2, 2026
  2. changed the title [-]Crash in emsdk 6.0.2 when calling UTF8ToString[/-] [+]JS exception/crash in emsdk 6.0.2 when calling UTF8ToString[/+] on Jul 2, 2026
  3. heyparth1 commented on Jul 2, 2026

    @heyparth1
    Contributor

    I'd like to work on this — opening a PR shortly.

  4. floooh commented on Jul 2, 2026

    @floooh
    CollaboratorAuthor

    ...oooof.... sorry for attacting the LLM bots...

  5. sbc100 commented on Jul 2, 2026

    @sbc100
    Collaborator

    Can you confirm by setting -sGROWABLE_ARRAYBUFFERS=0 to see if that fixes it?

  6. husker-dev commented on Jul 3, 2026

    @husker-dev

    @sbc100
    Encountered exactly the same problem. -sGROWABLE_ARRAYBUFFERS=0 fixed the issue for me.

  7. floooh commented on Jul 3, 2026

    @floooh
    CollaboratorAuthor

    @sbc100 yes, linking with -sGROWABLE_ARRAYBUFFERS=0 fixes the issue in emsdk 6.0.2

  8. assigned and unassigned on Jul 6, 2026
  9. sbc100 commented on Jul 6, 2026

    @sbc100
    Collaborator

    This will be fixed once we land #27242

  10. added a commit that references this issue on Jul 10, 2026
  11. added a commit that references this issue on Jul 10, 2026
    a41c221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions