Skip to content

Commit

Permalink
DIRECTOR: Fix memory corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Iskrich authored and sev- committed Aug 3, 2016
1 parent aaf8448 commit b208b8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions engines/director/director.cpp
Expand Up @@ -395,14 +395,14 @@ void DirectorEngine::loadSharedCastsFrom(Common::String filename) {
Common::SeekableSubReadStreamEndian *castStream = shardcst->getResource(MKTAG('V','W','C','R'), 1024);

castScore->loadCastData(*castStream);
_sharedCasts = castScore->_casts;
*_sharedCasts = castScore->_casts;

Common::Array<uint16> dib = shardcst->getResourceIDList(MKTAG('D','I','B',' '));

if (dib.size() != 0) {
Common::Array<uint16>::iterator iterator;
for (iterator = dib.begin(); iterator != dib.end(); ++iterator) {
_sharedDIB[*iterator] = shardcst->getResource(MKTAG('D','I','B',' '), *iterator);
_sharedDIB->setVal(*iterator, shardcst->getResource(MKTAG('D','I','B',' '), *iterator));
}
}

Expand All @@ -411,7 +411,7 @@ void DirectorEngine::loadSharedCastsFrom(Common::String filename) {
if (stxt.size() != 0) {
Common::Array<uint16>::iterator iterator;
for (iterator = stxt.begin(); iterator != stxt.end(); ++iterator) {
_sharedSTXT[*iterator] = shardcst->getResource(MKTAG('S','T','X','T'), *iterator);
_sharedSTXT->setVal(*iterator, shardcst->getResource(MKTAG('S','T','X','T'), *iterator));
}
}

Expand All @@ -420,7 +420,7 @@ void DirectorEngine::loadSharedCastsFrom(Common::String filename) {
if (stxt.size() != 0) {
Common::Array<uint16>::iterator iterator;
for (iterator = sound.begin(); iterator != sound.end(); ++iterator) {
_sharedSTXT[*iterator] = shardcst->getResource(MKTAG('S','N','D',' '), *iterator);
_sharedSound->setVal(*iterator, shardcst->getResource(MKTAG('S','N','D',' '), *iterator));
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions engines/director/director.h
Expand Up @@ -24,6 +24,7 @@
#define DIRECTOR_DIRECTOR_H

#include "common/scummsys.h"
#include "common/substream.h"

#include "common/str.h"
#include "common/hashmap.h"
Expand Down Expand Up @@ -67,9 +68,9 @@ class DirectorEngine : public ::Engine {
const byte *getPalette() const { return _currentPalette; }
uint16 getPaletteColorCount() const { return _currentPaletteLength; }
void loadSharedCastsFrom(Common::String filename);
Common::HashMap<int, Common::SeekableReadStream *> getSharedDIB() const { return _sharedDIB; }
Common::HashMap<int, Common::SeekableReadStream *> getSharedSTXT() const { return _sharedSTXT; }
Common::HashMap<int, Cast *> getSharedCasts() const { return _sharedCasts; }
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *getSharedDIB() const { return _sharedDIB; }
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *getSharedSTXT() const { return _sharedSTXT; }
Common::HashMap<int, Cast *> *getSharedCasts() const { return _sharedCasts; }

Common::HashMap<Common::String, Score *> *_movies;
Score *_currentScore;
Expand All @@ -93,10 +94,10 @@ class DirectorEngine : public ::Engine {
Common::String readPascalString(Common::SeekableReadStream &stream);

Common::String _sharedMMM;
Common::HashMap<int, Cast *> _sharedCasts;
Common::HashMap<int, Common::SeekableReadStream *> _sharedDIB;
Common::HashMap<int, Common::SeekableReadStream *> _sharedSTXT;
Common::HashMap<int, Common::SeekableReadStream *> _sharedSound;
Common::HashMap<int, Cast *> *_sharedCasts;
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *_sharedDIB;
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *_sharedSTXT;
Common::HashMap<int, Common::SeekableSubReadStreamEndian *> *_sharedSound;

Archive *_mainArchive;
Common::MacResManager *_macBinary;
Expand Down
8 changes: 4 additions & 4 deletions engines/director/score.cpp
Expand Up @@ -1129,11 +1129,11 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) {

Cast *cast;
if (!_vm->_currentScore->_casts.contains(_sprites[i]->_castId)) {
if (!_vm->getSharedCasts().contains(_sprites[i]->_castId)) {
if (!_vm->getSharedCasts()->contains(_sprites[i]->_castId)) {
warning("Cast id %d not found", _sprites[i]->_castId);
continue;
} else {
cast = _vm->getSharedCasts().getVal(_sprites[i]->_castId);
cast = _vm->getSharedCasts()->getVal(_sprites[i]->_castId);
}
} else {
cast = _vm->_currentScore->_casts[_sprites[i]->_castId];
Expand All @@ -1148,11 +1148,11 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) {
uint32 imgId = 1024 + _sprites[i]->_castId;

if (!_vm->_currentScore->getArchive()->hasResource(MKTAG('D', 'I', 'B', ' '), imgId)) {
if (!_vm->getSharedDIB().contains(imgId)) {
if (!_vm->getSharedDIB()->contains(imgId)) {
warning("DIB id %d not found", imgId);
continue;
} else {
img.loadStream(*_vm->getSharedDIB().getVal(imgId));
img.loadStream(*_vm->getSharedDIB()->getVal(imgId));
}
} else {
img.loadStream(*_vm->_currentScore->getArchive()->getResource(MKTAG('D', 'I', 'B', ' '), imgId));
Expand Down

0 comments on commit b208b8e

Please sign in to comment.