Skip to content

Error in UTF8ToString when calling wgpuDeviceCreateShaderModule #20453

Closed as not planned
@Ravbug

Description

@Ravbug

When calling wgpuDeviceCreateShaderModule, occasionally the call will fail with
Invalid UTF-8 leading byte 0x00000090 encountered when deserializing a UTF-8 string in wasm memory to a JS string!

Code that's causing the error:

void ShaderLibraryWG::InitFromShaderSource(decltype(owningDevice) owningDevice, const std::string_view shadercode){
        WGPUShaderModuleWGSLDescriptor shaderCodeDesc;
        shaderCodeDesc.chain.next = nullptr;
        shaderCodeDesc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
        shaderCodeDesc.code = shadercode.data();
        WGPUShaderModuleDescriptor moduleDesc;
        moduleDesc.nextInChain = &shaderCodeDesc.chain;
        shaderModule = wgpuDeviceCreateShaderModule(owningDevice->device, &moduleDesc);
    }

The shader string:

diagnostic(off, derivative_uniformity);

var<private> outColor : vec4f;

var<private> fragColor : vec3f;

fn main_1() {
  let x_14 : vec3f = fragColor;
  outColor = vec4f(x_14.x, x_14.y, x_14.z, 1.0f);
  return;
}

struct main_out {
  @location(0)
  outColor_1 : vec4f,
}

@fragment
fn main(@location(0) fragColor_param : vec3f) -> main_out {
  fragColor = fragColor_param;
  main_1();
  return main_out(outColor);
}

Call stack:
image

Maybe the issue is related to #20124 and that the shader source string in WGPUShaderModuleWGSLDescriptor is non-owning? Sometimes the code works without issues.

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.48-git (5b63268c904dd0e542f9c45e2b136c3d4a0bd638)
clang version 18.0.0 (https://github.com/llvm/llvm-project 25da11541c0740950e812a85d332a6d5cf4a5f87)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\Users\Admin\Documents\emsdk\upstream\bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions