GRIM/Movie: Lock the frame mutex when restoring a savegame.

Fix a race condition which could make it seek to time 0 instead of the time
saved in the savegame.
This commit is contained in:
Giulio Camuffo
2013-01-14 14:35:36 +01:00
parent cafe925961
commit d052d6259d
4 changed files with 30 additions and 11 deletions
+6
View File
@@ -180,6 +180,7 @@ bool MoviePlayer::loadFile(Common::String filename) {
}
void MoviePlayer::saveState(SaveGame *state) {
Common::StackLock lock(_frameMutex);
state->beginSection('SMUS');
state->writeString(_fname);
@@ -192,10 +193,13 @@ void MoviePlayer::saveState(SaveGame *state) {
state->writeLESint32(_x);
state->writeLESint32(_y);
save(state);
state->endSection();
}
void MoviePlayer::restoreState(SaveGame *state) {
Common::StackLock lock(_frameMutex);
state->beginSection('SMUS');
_fname = state->readString();
@@ -214,6 +218,8 @@ void MoviePlayer::restoreState(SaveGame *state) {
_frame = frame;
_movieTime = movieTime;
restore(state);
state->endSection();
}
+21 -7
View File
@@ -80,14 +80,10 @@ public:
/**
* Saves the state of the video to a savegame
*
* If you overload this in a subclass, call this first thing in the
* overloaded function
*
* @param state the state to save to
* @param state The state to save to
*/
virtual void saveState(SaveGame *state);
virtual void restoreState(SaveGame *state);
void saveState(SaveGame *state);
void restoreState(SaveGame *state);
protected:
static void timerCallback(void *ptr);
@@ -151,6 +147,24 @@ protected:
* @param filename The filename to be handled.
*/
virtual bool loadFile(Common::String filename);
/**
* Saves subclass related state of the video to a savegame
* The base implementation of this does nothing, but it can be overridden
* by subclasses.
*
* @param state The state to save to
*/
virtual void save(SaveGame *state) {}
/**
* Restores subclass related state of the video to a savegame
* The base implementation of this does nothing, but it can be overridden
* by subclasses.
*
* @param state The state to restore from
*/
virtual void restore(SaveGame *state) {}
};
+1 -3
View File
@@ -78,9 +78,7 @@ void SmushPlayer::postHandleFrame() {
}
}
void SmushPlayer::restoreState(SaveGame *state) {
MoviePlayer::restoreState(state);
Common::StackLock lock(_frameMutex);
void SmushPlayer::restore(SaveGame *state) {
if (isPlaying()) {
_smushDecoder->seek((uint32)_movieTime); // Currently not fully working (out of synch)
_smushDecoder->start();
+2 -1
View File
@@ -33,7 +33,8 @@ class SmushPlayer : public MoviePlayer {
public:
SmushPlayer(bool demo);
void restoreState(SaveGame *state);
void restore(SaveGame *state);
private:
bool loadFile(Common::String filename);
void handleFrame();