Skip to content

Commit

Permalink
avm2: avoid enqueuing Sound.play an infinite amount of times (#17425)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxarcher authored Aug 13, 2024
1 parent 3b9d9cf commit fdd86c1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/avm2/object/sound_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::avm2::value::Value;
use crate::avm2::Avm2;
use crate::avm2::Error;
use crate::avm2::EventObject;
use crate::backend::audio::SoundHandle;
use crate::backend::audio::{AudioManager, SoundHandle};
use crate::context::UpdateContext;
use crate::display_object::SoundTransform;
use crate::string::AvmString;
Expand Down Expand Up @@ -123,6 +123,12 @@ impl<'gc> SoundObject<'gc> {
.borrow_mut();
match &mut *sound_data {
SoundData::NotLoaded { queued_plays } => {
// Avoid to enqueue more unloaded sounds than the maximum allowed to be played
if queued_plays.len() >= AudioManager::MAX_SOUNDS {
tracing::warn!("Sound.play: too many unloaded sounds queued");
return Ok(false);
}

queued_plays.push(queued);
// We don't know the length yet, so return the `SoundChannel`
Ok(true)
Expand Down

0 comments on commit fdd86c1

Please sign in to comment.