diff options
author | Matthew Hoops | 2009-12-31 05:11:58 +0000 |
---|---|---|
committer | Matthew Hoops | 2009-12-31 05:11:58 +0000 |
commit | 7d131627fe6296ea4ce46db62900e4800b6b6816 (patch) | |
tree | 9391e8a616819ffc2b0bbb844b9abfdf86cf5c0e /engines | |
parent | eb2e45781749c31b2bd637fb40b6e0315d2601b6 (diff) | |
download | scummvm-rg350-7d131627fe6296ea4ce46db62900e4800b6b6816.tar.gz scummvm-rg350-7d131627fe6296ea4ce46db62900e4800b6b6816.tar.bz2 scummvm-rg350-7d131627fe6296ea4ce46db62900e4800b6b6816.zip |
Overload the = operator for SciArray which fixes the setType errors in GK1. Some other cleanup too. GK1 can now access the restore menu and get a bit further in the game (until a segfault in the Decompressor code).
svn-id: r46789
Diffstat (limited to 'engines')
-rw-r--r-- | engines/sci/engine/seg_manager.cpp | 2 | ||||
-rw-r--r-- | engines/sci/engine/segment.h | 36 |
2 files changed, 37 insertions, 1 deletions
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp index 755e44c543..4983d9b347 100644 --- a/engines/sci/engine/seg_manager.cpp +++ b/engines/sci/engine/seg_manager.cpp @@ -1299,6 +1299,7 @@ void SegManager::freeArray(reg_t addr) { if (!arrayTable->isValidEntry(addr.offset)) error("Attempt to use non-array %04x:%04x as array", PRINT_REG(addr)); + arrayTable->_table[addr.offset].destroy(); arrayTable->freeEntry(addr.offset); } @@ -1338,6 +1339,7 @@ void SegManager::freeString(reg_t addr) { if (!stringTable->isValidEntry(addr.offset)) error("Attempt to use non-string %04x:%04x as string", PRINT_REG(addr)); + stringTable->_table[addr.offset].destroy(); stringTable->freeEntry(addr.offset); } diff --git a/engines/sci/engine/segment.h b/engines/sci/engine/segment.h index a57c9766ae..d8cdd91da8 100644 --- a/engines/sci/engine/segment.h +++ b/engines/sci/engine/segment.h @@ -675,9 +675,40 @@ public: _size = 0; _actualSize = 0; } + + SciArray(const SciArray<T> &array) { + _type = array._type; + _size = array._size; + _actualSize = array._actualSize; + _data = new T[_actualSize]; + assert(_data); + memcpy(_data, array._data, _size * sizeof(T)); + } + + SciArray<T>& operator=(const SciArray<T> &array) { + if (this == &array) + return *this; + + delete[] _data; + _type = array._type; + _size = array._size; + _actualSize = array._actualSize; + _data = new T[_actualSize]; + assert(_data); + memcpy(_data, array._data, _size * sizeof(T)); + + return *this; + } - ~SciArray() { + virtual ~SciArray() { + destroy(); + } + + virtual void destroy() { delete[] _data; + _data = NULL; + _type = -1; + _size = _actualSize = 0; } void setType(byte type) { @@ -749,6 +780,9 @@ class SciString : public SciArray<char> { public: SciString() : SciArray<char>() { setType(3); } + // We overload destroy to ensure the string type is 3 after destroying + void destroy() { _type = 3; } + Common::String toString(); void fromString(Common::String string); }; |