mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user