Skip to content

Commit a255bc6

Browse files
Toad06torokati44
authored andcommitted
core: Stop sounds attached to an unloaded root movie
1 parent 50df827 commit a255bc6

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

core/src/backend/audio.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,26 @@ impl<'gc> AudioManager<'gc> {
532532
});
533533
}
534534

535+
/// Stops any sound associated with the given Display Object and its children. The DO must represent the parent.
536+
/// Sounds associated with DOs are an AVM1/Timeline concept and should not be called from AVM2 scripts.
537+
pub fn stop_sounds_on_parent_and_children(
538+
&mut self,
539+
audio: &mut dyn AudioBackend,
540+
display_object: DisplayObject<'gc>,
541+
) {
542+
self.sounds.retain(move |sound| {
543+
let mut other = sound.display_object;
544+
while let Some(other_do) = other {
545+
if DisplayObject::ptr_eq(other_do, display_object) {
546+
audio.stop_sound(sound.instance);
547+
return false;
548+
}
549+
other = other_do.parent();
550+
}
551+
true
552+
});
553+
}
554+
535555
pub fn stop_all_sounds(&mut self, audio: &mut dyn AudioBackend) {
536556
self.sounds.clear();
537557
audio.stop_all_sounds();

core/src/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ impl<'gc> UpdateContext<'gc> {
287287
.stop_sounds_with_display_object(self.audio, display_object)
288288
}
289289

290+
pub fn stop_sounds_on_parent_and_children(&mut self, display_object: DisplayObject<'gc>) {
291+
self.audio_manager
292+
.stop_sounds_on_parent_and_children(self.audio, display_object)
293+
}
294+
290295
pub fn stop_all_sounds(&mut self) {
291296
self.audio_manager.stop_all_sounds(self.audio)
292297
}

core/src/display_object.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,10 +2147,6 @@ pub trait TDisplayObject<'gc>:
21472147
}
21482148
}
21492149

2150-
context
2151-
.audio_manager
2152-
.stop_sounds_with_display_object(context.audio, (*self).into());
2153-
21542150
self.set_avm1_removed(context.gc_context, true);
21552151
}
21562152

core/src/display_object/avm1_button.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,7 @@ impl<'gc> TDisplayObject<'gc> for Avm1Button<'gc> {
404404
} else if let Some(node) = self.masker() {
405405
node.set_maskee(context.gc(), None, true);
406406
}
407-
context
408-
.audio_manager
409-
.stop_sounds_with_display_object(context.audio, (*self).into());
407+
410408
self.set_avm1_removed(context.gc(), true);
411409
}
412410
}

core/src/display_object/edit_text.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,10 +2413,6 @@ impl<'gc> TDisplayObject<'gc> for EditText<'gc> {
24132413
.retain(|&text_field| !DisplayObject::ptr_eq(text_field.into(), (*self).into()));
24142414
}
24152415

2416-
context
2417-
.audio_manager
2418-
.stop_sounds_with_display_object(context.audio, (*self).into());
2419-
24202416
self.set_avm1_removed(context.gc_context, true);
24212417
}
24222418
}

core/src/display_object/movie_clip.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,9 +2925,11 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
29252925
mc.stop_audio_stream(context);
29262926
}
29272927

2928-
context
2929-
.audio_manager
2930-
.stop_sounds_with_display_object(context.audio, (*self).into());
2928+
if self.is_root() {
2929+
context
2930+
.audio_manager
2931+
.stop_sounds_on_parent_and_children(context.audio, (*self).into());
2932+
}
29312933

29322934
// If this clip is currently pending removal, then it unload event will have already been dispatched
29332935
if !self.avm1_pending_removal() {

0 commit comments

Comments
 (0)