-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Problem
Today, the emscripten_destroy_web_audio_node function only disconnects the AudioNode and removes it from the registry.
This does not guarantee that process() callback wont be called again, and therefore the registered callback in emscripten_create_wasm_audio_worklet_node might continue to be called.
If the userData pointer is used, it might be very hard to free that resource without risking use after free.
Suggested solution
When emscripten_destroy_web_audio_node is used, send a message to the Node, what will set a property to ensure that any access to WASM memory will no longer happen.
Since the existing function would not have a way of knowing when it is safe to free any resource connected to the userData pointer. I also suggest adding an additional function (emscripten_destroy_web_audio_node_async or similar), that will get a callback when we can ensure that no more calls to the registered EmscriptenWorkletNodeProcessCallback will happen.
I'm unsure if the callback should happen on the main thread, or in the AudioContext.
POC: main...lindell:emscripten:better-destroy
Trying to get the tests to run results in failure even on main for me. But if this approach seems fine, I will go for a proper implementation with working tests.