Skip to content

Same AudioContext for two Modules causes memory corruption #25788

@lindell

Description

@lindell

Version of emscripten/emsdk:
4.0.13 (but verified in code this should still exist on HEAD)

Description:

Using the web audio API with one AudioContext but with two or more modules does not work, as the second one will try silently the memory of the first one, causing memory failures.

Example:

  const audioContext = new AudioContext();

  const mainModule = await createModule();
  const audioContextId = mainModule.emscriptenRegisterAudioObject(audioContext);
  mainModule.functionThatStartsAWorklet(audioContextId);

  const mainModule2 = await createModule();
  const audioContextId2 =
    mainModule2.emscriptenRegisterAudioObject(audioContext);
  mainModule2.functionThatStartsAnotherWorklet(audioContextId2);

Where functionThatStartsAWorklet and functionThatStartsAnotherWorklet starts AudioWorklets.


addModule will succeed, at least if the same URL is used.

But since it is set up with the wasmModule and memory only once for the AudioContext. When starting another worklet, from another module, both will use the same memory even though they should be using separate ones. This causes memory corruptions, and usually crashes for one or both of the worklets.

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