Skip to content

Commit

Permalink
SCUMM: Lock the sound resource while the music is playing
Browse files Browse the repository at this point in the history
After some discussion on #scummvm, the player now locks the sound
resource while the music is playing. This prevents the resource
manager from expiring the resource, which at best could cause
music to restart where it shouldn't.. At worst, I guess it could
have crashed, but I never saw that happen.
  • Loading branch information
Torbjörn Andersson committed Nov 18, 2012
1 parent ae823b5 commit 94b0881
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion engines/scumm/player_mac.cpp
Expand Up @@ -25,6 +25,7 @@
#include "engines/engine.h"
#include "gui/message.h"
#include "scumm/player_mac.h"
#include "scumm/resource.h"
#include "scumm/scumm.h"
#include "scumm/imuse/imuse.h"

Expand Down Expand Up @@ -163,6 +164,9 @@ void Player_Mac::setMusicVolume(int vol) {
}

void Player_Mac::stopAllSounds_Internal() {
if (_soundPlaying != -1) {
_vm->_res->unlock(rtSound, _soundPlaying);
}
_soundPlaying = -1;
for (int i = 0; i < _numberOfChannels; i++) {
// The channel data is managed by the resource manager, so
Expand Down Expand Up @@ -194,18 +198,20 @@ void Player_Mac::startSound(int nr) {
Common::StackLock lock(_mutex);
debug(5, "Player_Mac::startSound(%d)", nr);

stopAllSounds_Internal();

const byte *ptr = _vm->getResourceAddress(rtSound, nr);
assert(ptr);

if (!loadMusic(ptr)) {
return;
}

_vm->_res->lock(rtSound, nr);
_soundPlaying = nr;
}

bool Player_Mac::Channel::loadInstrument(Common::SeekableReadStream *stream) {
// Load the sound
uint16 soundType = stream->readUint16BE();
if (soundType != 1) {
warning("Player_Mac::loadInstrument: Unsupported sound type %d", soundType);
Expand Down

0 comments on commit 94b0881

Please sign in to comment.