[Scummvm-git-logs] scummvm master -> 4368a4f69dad822ae45901fd6066049454a5ec58

NMIError noreply at scummvm.org
Thu Nov 23 21:08:38 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4368a4f69d LURE: Fix duplicate looping sounds


Commit: 4368a4f69dad822ae45901fd6066049454a5ec58
    https://github.com/scummvm/scummvm/commit/4368a4f69dad822ae45901fd6066049454a5ec58
Author: Coen Rampen (crampen at gmail.com)
Date: 2023-11-23T22:08:30+01:00

Commit Message:
LURE: Fix duplicate looping sounds

Under some circumstances, looping sounds could be repeatedly triggered and
multiple copies of the same sound would stack up and consume all the sound
channels. Additionally, this could cause a crash because the code did not deal
well with this situation.
The engine will now check if a sound is already playing before adding it when
loading a savegame. It will also not try to play a sound if not enough channels
are available.

Changed paths:
    engines/lure/sound.cpp


diff --git a/engines/lure/sound.cpp b/engines/lure/sound.cpp
index 1e42685aa48..08677a90acf 100644
--- a/engines/lure/sound.cpp
+++ b/engines/lure/sound.cpp
@@ -114,7 +114,7 @@ void SoundManager::loadFromStream(Common::ReadStream *stream) {
 			SoundDescResource &rec = soundDescs()[soundIndex];
 			if ((rec.flags & SF_RESTORE) != 0)
 				// Requeue the sound for playing
-				addSound(soundIndex, false);
+				addSound2(soundIndex);
 		}
 	}
 }
@@ -542,13 +542,14 @@ void SoundManager::musicInterface_Play(uint8 soundNumber, bool isMusic, uint8 nu
 			}
 		}
 	}
-	if (source == -1)
+	if (source == -1) {
 		warning("Insufficient sources to play sound %i", soundNumber);
-	else
+	} else {
 		_sourcesInUse[source] = true;
-	MidiMusic *sound = new MidiMusic(_driver, soundNum, isMusic,
-		loop, source, numChannels, soundStart, dataSize, volume);
-	_playingSounds.push_back(MusicList::value_type(sound));
+		MidiMusic *sound = new MidiMusic(_driver, soundNum, isMusic,
+			loop, source, numChannels, soundStart, dataSize, volume);
+		_playingSounds.push_back(MusicList::value_type(sound));
+	}
 	_soundMutex.unlock();
 }
 
@@ -801,8 +802,13 @@ void MidiMusic::setVolume(int volume) {
 
 void MidiMusic::playMusic() {
 	debugC(ERROR_DETAILED, kLureDebugSounds, "MidiMusic::PlayMusic playing sound %d", _soundNumber);
-	if (Sound.isRoland() && !_isMusic)
-		_mt32Driver->allocateSourceChannels(_source, _numChannels);
+	if (Sound.isRoland() && !_isMusic) {
+		bool result = _mt32Driver->allocateSourceChannels(_source, _numChannels);
+		if (!result) {
+			stopMusic();
+			return;
+		}
+	}
 	_parser->loadMusic(_soundData, _soundSize);
 	_parser->setTrack(0);
 	_isPlaying = true;




More information about the Scummvm-git-logs mailing list