Skip to content

Fix GPUError message persistence in device.popErrorScope() #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 25, 2025

The device.popErrorScope() method was returning empty or garbage error messages instead of the actual WebGPU error text. This was caused by the GPUError class storing the error message as a char const * pointer, which became invalid after the WebGPU callback returned.

Problem

const redFragWGSL = `@fragment
fn main() -> @location(0) vec4f {
  return vec4(1.0, 0.0, 0.0, 1.0;  // Missing closing parenthesis
}`;

device.pushErrorScope('validation');
const redFragModule = device.createShaderModule({
  code: redFragWGSL,
});

const error = await device.popErrorScope();
if (error) {
  console.log('Error message: ', error.message);
  // Before: Empty string or garbage
  // Expected: "Error while parsing WGSL: :3:33 error: expected ',' for function call..."
}

Root Cause

The GPUError class was storing the error message as a char const * pointer:

class GPUError {
  wgpu::ErrorType type;
  char const *message;  // Problem: pointer becomes invalid after callback
};

When the WebGPU callback completed, the underlying string memory could be deallocated, leaving the pointer pointing to invalid memory.

Solution

Changed GPUError to store the message as a std::string to ensure proper string persistence:

class GPUError {
public:
  GPUError(wgpu::ErrorType aType, char const *aMessage)
      : type(aType), message(aMessage ? aMessage : "") {}  // Copy string safely

  wgpu::ErrorType type;
  std::string message;  // Stores actual string data
};

Changes Made

  • GPUError.h: Changed message field from char const * to std::string
  • Constructor: Added null-check and string copying
  • JSIConverter: Updated to use c_str() for proper string conversion
  • Tests: Added comprehensive test coverage for error scope functionality

Testing

Added ErrorScope.spec.ts with tests that verify:

  • Error messages are properly captured and returned with actual content
  • No errors are returned when no validation issues occur
  • Error messages contain meaningful WGSL parsing information

The fix is fully backward compatible with no API changes required.

Fixes #212.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • googlechromelabs.github.io
    • Triggering command: /usr/local/bin/node install.mjs (dns block)
  • https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.88/linux64/chrome-linux64.zip
    • Triggering command: /usr/local/bin/node install.mjs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…st *

Co-authored-by: wcandillon <306134+wcandillon@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Cannot access error messages from device.popErrorScope Fix GPUError message persistence in device.popErrorScope() Jun 25, 2025
@Copilot Copilot AI requested a review from wcandillon June 25, 2025 20:56
Copilot finished work on behalf of wcandillon June 25, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot access error messages from device.popErrorScope
2 participants