From dcd6a8d29d3cbc3450dcb86987779a16265c2b2e Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 19 Mar 2003 19:09:51 +0000 Subject: use a mutex to sync smush screen updates (should avoid crash caused by a race condition) svn-id: r6837 --- scumm/smush/smush_player.cpp | 42 ++++++++++++++++++++---------------------- scumm/smush/smush_player.h | 4 ++-- 2 files changed, 22 insertions(+), 24 deletions(-) (limited to 'scumm') diff --git a/scumm/smush/smush_player.cpp b/scumm/smush/smush_player.cpp index 4406bb8afa..e145f28623 100644 --- a/scumm/smush/smush_player.cpp +++ b/scumm/smush/smush_player.cpp @@ -218,10 +218,14 @@ SmushPlayer::SmushPlayer(Scumm *scumm, int speed, bool subtitles) { _speed = speed; _subtitles = subtitles; _smushProcessFrame = false; + + _mutex = _scumm->_system->create_mutex(); } SmushPlayer::~SmushPlayer() { deinit(); + if (_mutex) + _scumm->_system->delete_mutex (_mutex); } void SmushPlayer::init() { @@ -855,17 +859,15 @@ void SmushPlayer::setPalette(byte *palette) { } void SmushPlayer::updateScreen() { - if (_whileUpdate == false) { - _whileCopyRect = true; + _scumm->_system->lock_mutex(_mutex); - uint32 end_time, start_time = _scumm->_system->get_msecs(); - _scumm->_system->copy_rect(_data, _width, 0, 0, _width, _height); - _updateNeeded = true; - end_time = _scumm->_system->get_msecs(); - debug(4, "Smush stats: updateScreen( %03d )", end_time - start_time); + uint32 end_time, start_time = _scumm->_system->get_msecs(); + _scumm->_system->copy_rect(_data, _width, 0, 0, _width, _height); + _updateNeeded = true; + end_time = _scumm->_system->get_msecs(); + debug(4, "Smush stats: updateScreen( %03d )", end_time - start_time); - _whileCopyRect = false; - } + _scumm->_system->unlock_mutex(_mutex); } void SmushPlayer::play(const char *filename, const char *directory) { @@ -876,8 +878,6 @@ void SmushPlayer::play(const char *filename, const char *directory) { return; } - _whileUpdate = false; - _whileCopyRect = false; _updateNeeded = false; setupAnim(filename, directory); @@ -887,17 +887,15 @@ void SmushPlayer::play(const char *filename, const char *directory) { _scumm->processKbd(); _scumm->waitForTimer(1); if(_updateNeeded == true) { - if(_whileCopyRect == false) { - _whileUpdate = true; - - uint32 end_time, start_time = _scumm->_system->get_msecs(); - _scumm->_system->update_screen(); - _updateNeeded = false; - end_time = _scumm->_system->get_msecs(); - debug(4, "Smush stats: BackendUpdateScreen( %03d )", end_time - start_time); - - _whileUpdate = false; - } + _scumm->_system->lock_mutex(_mutex); + + uint32 end_time, start_time = _scumm->_system->get_msecs(); + _scumm->_system->update_screen(); + _updateNeeded = false; + end_time = _scumm->_system->get_msecs(); + debug(4, "Smush stats: BackendUpdateScreen( %03d )", end_time - start_time); + + _scumm->_system->unlock_mutex(_mutex); } if (_scumm->_videoFinished == true) break; diff --git a/scumm/smush/smush_player.h b/scumm/smush/smush_player.h index 52c79aad3a..24952b1079 100644 --- a/scumm/smush/smush_player.h +++ b/scumm/smush/smush_player.h @@ -62,14 +62,14 @@ private: bool _alreadyInit; int _speed; bool _outputSound; + + void *_mutex; public: int _width, _height; byte *_data; bool _smushProcessFrame; - bool _whileUpdate; - bool _whileCopyRect; bool _updateNeeded; SmushPlayer(Scumm *, int, bool); -- cgit v1.2.3