@@ -7,7 +7,6 @@ use crate::render::{
77use crate :: { AudioBuffer , RENDER_QUANTUM_SIZE } ;
88
99use std:: any:: Any ;
10- use std:: sync:: Arc ;
1110
1211/// Options for constructing an [`ScriptProcessorNode`]
1312#[ derive( Clone , Debug ) ]
@@ -138,20 +137,25 @@ impl ScriptProcessorNode {
138137 /// the inputBuffer attribute. The audio data which is the result of the processing (or the
139138 /// synthesized data if there are no inputs) is then placed into the outputBuffer.
140139 ///
140+ /// The output buffer is shipped back to the render thread when the AudioProcessingEvent goes
141+ /// out of scope, so be sure not to store it somewhere.
142+ ///
141143 /// Only a single event handler is active at any time. Calling this method multiple times will
142144 /// override the previous event handler.
143145 pub fn set_onaudioprocess < F : FnMut ( AudioProcessingEvent ) + Send + ' static > (
144146 & self ,
145147 mut callback : F ,
146148 ) {
147- // TODO, hack: use Arc to prevent drop of AudioContextRegistration
148- let registration = Arc :: new ( self . registration . clone ( ) ) ;
149+ // We need these fields to ship the output buffer to the render thread
150+ let base = self . registration ( ) . context ( ) . clone ( ) ;
151+ let id = self . registration ( ) . id ( ) ;
152+
149153 let callback = move |v| {
150154 let mut payload = match v {
151155 EventPayload :: AudioProcessing ( v) => v,
152156 _ => unreachable ! ( ) ,
153157 } ;
154- payload. registration = Some ( Arc :: clone ( & registration ) ) ;
158+ payload. registration = Some ( ( base . clone ( ) , id ) ) ;
155159 callback ( payload) ;
156160 } ;
157161
0 commit comments