diff options
-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); }; |