Skip to content

AudioWorkletNode crashes with "expect Object, got: Undefined" during OfflineAudioContext.startRendering() #170

@Catsvilles

Description

@Catsvilles

AudioWorkletNode crashes during startRendering() on OfflineAudioContext with error expect Object, got: Undefined. The error originates from the native Rust function run_audio_worklet_global_scope(). This happens even with the simplest possible passthrough processor.

Reproduction

import { OfflineAudioContext, AudioWorkletNode } from 'node-web-audio-api';
import fs from 'node:fs';

// Minimal passthrough processor
fs.writeFileSync('/tmp/test-processor.js', `
class TestProcessor extends AudioWorkletProcessor {
  process(inputs, outputs) {
    if (inputs[0] && inputs[0][0] && outputs[0] && outputs[0][0]) {
      for (let ch = 0; ch < outputs[0].length; ch++) {
        if (inputs[0][ch]) outputs[0][ch].set(inputs[0][ch]);
      }
    }
    return true;
  }
}
registerProcessor('test-processor', TestProcessor);
`);

const ctx = new OfflineAudioContext(2, 48000, 48000);
await ctx.audioWorklet.addModule('/tmp/test-processor.js'); // succeeds
const osc = ctx.createOscillator();
const node = new AudioWorkletNode(ctx, 'test-processor'); // succeeds
osc.connect(node);
node.connect(ctx.destination);
osc.start(0);
osc.stop(1);
await ctx.startRendering(); // CRASHES
Error

Error: expect Object, got: Undefined
    at Immediate.runLoop (node_modules/node-web-audio-api/js/AudioWorkletGlobalScope.js:112:3)
    at process.processImmediate (node:internal/timers:511:21) {
  code: 'InvalidArg'
}

Environment
node-web-audio-api@1.0.8
macOS arm64 (Apple Silicon) — binary: node-web-audio-api.darwin-arm64.node
Tested on Node.js v18.12.1, v22.22.1, v23.2.0 — same crash on all three

Notes
addModule() completes successfully
AudioWorkletNode constructor completes successfully
The crash occurs only when startRendering() (or audio processing in AudioContext) actually invokes the worklet's process() method

The error comes from the native Rust side (run_audio_worklet_global_scope), suggesting the JS↔Rust bridge fails to marshal the processor instance or its process() return value
Also tested with processors that have parameterDescriptors — same result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions