avm2: avoid enqueuing Sound.play an infinite amount of times (#17425)

This commit is contained in:
Marco Bartoli 2024-08-13 17:57:22 +02:00 committed by GitHub
parent 3b9d9cf230
commit fdd86c1da2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 1 deletions

View File

@ -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;
@ -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)