From 036c56370ca15e8d575d35d4899daa53e38037fe Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 13 Jun 2019 20:27:33 -1000 Subject: [PATCH] Various memory-related bug fixes Also new lzokay API to reduce erroneous usage. --- dewfile.json | 6 +++--- src/Core/CompressionUtil.cpp | 13 +++++++------ src/Core/Resource/Script/Property/CArrayProperty.h | 2 +- src/Core/Resource/StringTable/CStringTable.cpp | 3 ++- src/Editor/WorldEditor/CWorldEditor.cpp | 5 +++++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dewfile.json b/dewfile.json index e344126a..50a6f223 100644 --- a/dewfile.json +++ b/dewfile.json @@ -32,10 +32,10 @@ }, { "name": "lzokay", - "url": "https://github.com/sfuller/lzokay", + "url": "https://github.com/jackoalan/lzokay", "type": "git", - "head": "cmake", - "ref": "87467048df10e72540a5abcac9dd5c0c4df3a712" + "head": "master", + "ref": "343f9707f6ab2143d3455c93d8b7570a0ffcee97" }, { "name": "tinyxml2", diff --git a/src/Core/CompressionUtil.cpp b/src/Core/CompressionUtil.cpp index cdcd7b9b..d02f1624 100644 --- a/src/Core/CompressionUtil.cpp +++ b/src/Core/CompressionUtil.cpp @@ -102,11 +102,11 @@ namespace CompressionUtil else return true; } - bool DecompressLZO(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32& rTotalOut) + bool DecompressLZO(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32 DstLen, uint32& rTotalOut) { #if USE_LZOKAY - size_t TotalOut = rTotalOut; - lzokay::EResult Result = lzokay::decompress(pSrc, (size_t) SrcLen, pDst, TotalOut); + size_t TotalOut; + lzokay::EResult Result = lzokay::decompress(pSrc, (size_t) SrcLen, pDst, DstLen, TotalOut); rTotalOut = TotalOut; if (Result < lzokay::EResult::Success) @@ -172,7 +172,7 @@ namespace CompressionUtil // No zlib magic - this is LZO else { - bool Success = DecompressLZO(pSrc, Size, pDst, TotalOut); + bool Success = DecompressLZO(pSrc, Size, pDst, (uint32) (pDstEnd - pDst), TotalOut); if (!Success) return false; } @@ -220,8 +220,9 @@ namespace CompressionUtil bool CompressLZO(uint8 *pSrc, uint32 SrcLen, uint8 *pDst, uint32 DstLen, uint32& rTotalOut) { #if USE_LZOKAY - rTotalOut = DstLen; - lzokay::EResult Result = lzokay::compress(pSrc, (size_t) SrcLen, pDst, (size_t&) rTotalOut); + size_t TotalOut; + lzokay::EResult Result = lzokay::compress(pSrc, (size_t) SrcLen, pDst, DstLen, TotalOut); + rTotalOut = TotalOut; if (Result < lzokay::EResult::Success) { diff --git a/src/Core/Resource/Script/Property/CArrayProperty.h b/src/Core/Resource/Script/Property/CArrayProperty.h index 147a0d1b..3ec53da4 100644 --- a/src/Core/Resource/Script/Property/CArrayProperty.h +++ b/src/Core/Resource/Script/Property/CArrayProperty.h @@ -70,7 +70,7 @@ public: virtual void Destruct(void* pData) const { RevertToDefault(pData); - TTypedProperty::Destruct(pData); + _GetInternalArray(pData).~SScriptArray(); } virtual bool MatchesDefault(void* pData) const diff --git a/src/Core/Resource/StringTable/CStringTable.cpp b/src/Core/Resource/StringTable/CStringTable.cpp index aae2fbfb..3bd4a8e6 100644 --- a/src/Core/Resource/StringTable/CStringTable.cpp +++ b/src/Core/Resource/StringTable/CStringTable.cpp @@ -280,7 +280,8 @@ CDependencyTree* CStringTable::BuildDependencyTree() const { if (Game() >= EGame::CorruptionProto) { - ASSERT(ParamString.StartsWith("0x")); + if (!ParamString.StartsWith("0x")) + continue; ParamString = ParamString.ChopFront(2); } diff --git a/src/Editor/WorldEditor/CWorldEditor.cpp b/src/Editor/WorldEditor/CWorldEditor.cpp index 79ebb0de..41772277 100644 --- a/src/Editor/WorldEditor/CWorldEditor.cpp +++ b/src/Editor/WorldEditor/CWorldEditor.cpp @@ -219,6 +219,11 @@ CWorldEditor::CWorldEditor(QWidget *parent) CWorldEditor::~CWorldEditor() { + mScene.ClearScene(); + mpArea = nullptr; + mpWorld = nullptr; + gpResourceStore->DestroyUnreferencedResources(); // this should destroy the area! + delete mpScriptSidebar; // For some reason WCreateTab filters an event during the viewport's destructor delete ui; }