[Scummvm-git-logs] scummvm branch-2-3 -> 74ffddd8454163b1057c77ffdb0df9f2b4b4b85c
NMIError
60350957+NMIError at users.noreply.github.com
Tue Aug 31 21:33:27 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:
74ffddd845 CGE2: Stop current SFX before loading a new one
Commit: 74ffddd8454163b1057c77ffdb0df9f2b4b4b85c
https://github.com/scummvm/scummvm/commit/74ffddd8454163b1057c77ffdb0df9f2b4b4b85c
Author: Coen Rampen (crampen at gmail.com)
Date: 2021-08-31T23:33:19+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