diff --git a/third_party/blink/renderer/modules/webaudio/audio_worklet_processor.cc b/third_party/blink/renderer/modules/webaudio/audio_worklet_processor.cc index 9d4533f75be6e0..ad7a35484c9655 100644 --- a/third_party/blink/renderer/modules/webaudio/audio_worklet_processor.cc +++ b/third_party/blink/renderer/modules/webaudio/audio_worklet_processor.cc @@ -466,7 +466,11 @@ bool AudioWorkletProcessor::Process( TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("audio-worklet"), "AudioWorkletProcessor::Process"); - DCHECK(global_scope_->IsContextThread()); + // Process() enters the AudioWorklet's v8::Isolate via ScriptState::Scope + // below. V8 isolates are single-threaded; entering from a thread that does + // not own the isolate is undefined behavior (HandleScopeData / heap races). + // Upgrade to CHECK so a stale render-thread task runner cannot reach V8. + CHECK(global_scope_->IsContextThread()); DCHECK(!hasErrorOccurred()); ScriptState* script_state = diff --git a/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.cc b/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.cc index 6db772e60558e5..a81df0b73b0f45 100644 --- a/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.cc +++ b/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.cc @@ -374,4 +374,17 @@ void OfflineAudioDestinationHandler::RestartRendering() { PrepareTaskRunnerForRendering(); } +void OfflineAudioDestinationHandler::PrepareTaskRunnerForWorklet() { + DCHECK(IsMainThread()); + + // Called from BaseAudioContext::NotifyWorkletIsReady() while the context is + // suspended. If startRendering() has already created `render_thread_`, that + // thread's task runner is now stale: rendering must move to the AudioWorklet + // thread (which owns the V8 isolate that AudioWorkletProcessor::Process() + // will enter). Re-run the same task-runner selection logic so a subsequent + // resume() posts DoOfflineRendering to the worklet thread instead of the + // stale NonMainThread. + PrepareTaskRunnerForRendering(); +} + } // namespace blink diff --git a/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.h b/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.h index 461facfdf0bcf1..b3c9dd5ba9e01e 100644 --- a/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.h +++ b/third_party/blink/renderer/modules/webaudio/offline_audio_destination_handler.h @@ -47,7 +47,7 @@ class OfflineAudioDestinationHandler final : public AudioDestinationHandler { void Pause() override; void Resume() override; uint32_t MaxChannelCount() const override; - void PrepareTaskRunnerForWorklet() override {} + void PrepareTaskRunnerForWorklet() override; void RestartRendering() override;