[Scummvm-git-logs] scummvm master -> 36d395b2d14f14360afd53313e02011890f1f7a8

NMIError 60350957+NMIError at users.noreply.github.com
Tue Aug 31 21:32:42 UTC 2021


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:
36d395b2d1 CGE2: Stop current SFX before loading a new one


Commit: 36d395b2d14f14360afd53313e02011890f1f7a8
    https://github.com/scummvm/scummvm/commit/36d395b2d14f14360afd53313e02011890f1f7a8
Author: Coen Rampen (crampen at gmail.com)
Date: 2021-08-31T23:31:54+02:00

Commit Message:
CGE2: Stop current SFX before loading a new one

When loading a sound effect, the engine would deallocate the memory for the
currently playing sound effect, and stop playback afterwards. This commit
changes this to stop playback first, and then deallocate and load the new
sound effect.

This should fix the problem with the mixer accessing deallocated memory
reported in issue #12852.

Changed paths:
    engines/cge2/snail.cpp
    engines/cge2/sound.cpp
    engines/cge2/sound.h


diff --git a/engines/cge2/snail.cpp b/engines/cge2/snail.cpp
index e8e30ac6c9..dd64d68ff7 100644
--- a/engines/cge2/snail.cpp
+++ b/engines/cge2/snail.cpp
@@ -63,7 +63,7 @@ void CommandHandler::runCommand() {
 		if (_vm->_fx->exist(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0])) {
 			int16 oldRepeat = _vm->_sound->getRepeat();
 			_vm->_sound->setRepeat(1);
-			_vm->_sound->play(Audio::Mixer::kSpeechSoundType, _vm->_fx->load(_vm->_soundStat._ref[1], _vm->_soundStat._ref[0]), _vm->_sound->_smpinf._span);
+			_vm->_sound->play(Audio::Mixer::kSpeechSoundType, _vm->_soundStat._ref[1], _vm->_soundStat._ref[0], _vm->_sound->_smpinf._span);
 			_vm->_sound->setRepeat(oldRepeat);
 			return;
 		}
@@ -607,7 +607,7 @@ void CGE2Engine::snSound(Sprite *spr, int wav, Audio::Mixer::SoundType soundType
 
 		_soundStat._ref[1] = wav;
 		_soundStat._ref[0] = !_fx->exist(_soundStat._ref[1]);
-		_sound->play(soundType, _fx->load(_soundStat._ref[1], _soundStat._ref[0]),
+		_sound->play(soundType, _soundStat._ref[1], _soundStat._ref[0],
 			(spr) ? (spr->_pos2D.x / (kScrWidth / 16)) : 8);
 	}
 }
diff --git a/engines/cge2/sound.cpp b/engines/cge2/sound.cpp
index 8e48f7b709..90903081da 100644
--- a/engines/cge2/sound.cpp
+++ b/engines/cge2/sound.cpp
@@ -63,7 +63,7 @@ void Sound::open() {
 	setRepeat(1);
 	if (_vm->_commandHandlerTurbo != nullptr)
 		_vm->switchSay();
-	play(Audio::Mixer::kSFXSoundType, _vm->_fx->load(99, 99));
+	play(Audio::Mixer::kSFXSoundType, 99, 99);
 }
 
 void Sound::setRepeat(int16 count) {
@@ -74,9 +74,10 @@ int16 Sound::getRepeat() {
 	return _soundRepeatCount;
 }
 
-void Sound::play(Audio::Mixer::SoundType soundType, DataCk *wav, int pan) {
+void Sound::play(Audio::Mixer::SoundType soundType, int ref, int sub, int pan) {
+	stop();
+	DataCk *wav = _vm->_fx->load(ref, sub);
 	if (wav) {
-		stop();
 		_smpinf._saddr = &*(wav->addr());
 		_smpinf._slen = (uint16)wav->size();
 		_smpinf._span = pan;
diff --git a/engines/cge2/sound.h b/engines/cge2/sound.h
index 835d665dbc..2e868c8bdb 100644
--- a/engines/cge2/sound.h
+++ b/engines/cge2/sound.h
@@ -70,7 +70,7 @@ public:
 	~Sound();
 	void open();
 	void close();
-	void play(Audio::Mixer::SoundType soundType, DataCk *wav, int pan = 8);
+	void play(Audio::Mixer::SoundType soundType, int ref, int sub, int pan = 8);
 	int16 getRepeat();
 	void setRepeat(int16 count);
 	void stop();




More information about the Scummvm-git-logs mailing list