From 882c1234cb2c04132aae24ab5072bd653efb09f0 Mon Sep 17 00:00:00 2001 From: Pawel Wojtasik Date: Tue, 19 Apr 2016 19:28:20 +0200 Subject: [PATCH] !B (Action) (CE-8897) (CE-8896) Fixed a memory management issue with a debug string instance being passed across a dll boundary. Removed the previous ad-hoc workaround for this issue to reduce complexity on the CryAction's client side. Review: ID 54575 by Author: Pawel Wojtasik, Reviewer: Hilko Cords Copied from Perforce Change: 1379807 --- Code/CryEngine/CryAction/ICryMannequin.h | 57 ---------------------- Code/CryEngine/CryAction/ICryMannequinDefs.h | 31 ++++++------ .../CryAction/Mannequin/AnimationDatabase.cpp | 10 ---- .../CryAction/Mannequin/AnimationDatabase.h | 5 -- 4 files changed, 15 insertions(+), 88 deletions(-) diff --git a/Code/CryEngine/CryAction/ICryMannequin.h b/Code/CryEngine/CryAction/ICryMannequin.h index 40a078fe0..7dccd97ce 100644 --- a/Code/CryEngine/CryAction/ICryMannequin.h +++ b/Code/CryEngine/CryAction/ICryMannequin.h @@ -942,8 +942,6 @@ typedef void (* MannAssetCallback)(const SAnimAssetReport& assetReport, void* _c class IAnimationDatabase { - friend class SFragmentDataRAII; - public: virtual ~IAnimationDatabase() {} @@ -987,61 +985,6 @@ public: virtual bool ClearSubADBFilter(const string& sADBFileName) = 0; virtual void QueryUsedTags(const FragmentID fragmentID, const SFragTagState& filter, SFragTagState& usedTags) const = 0; - -protected: - - //! Factory method for SFragmentData, to handle dll-scope - virtual SFragmentData* CreateSFragmentDataRaw() const = 0; - virtual void DestroySFragmentDataRaw(SFragmentData* ptr) const = 0; -}; - -class SFragmentDataRAII -{ -public: - - SFragmentDataRAII(const IAnimationDatabase* adb) : m_adb(adb), m_sfd(nullptr) - { - if (m_adb) - { - m_sfd = m_adb->CreateSFragmentDataRaw(); - } - } - - ~SFragmentDataRAII() - { - Clear(); - } - - SFragmentData* Get() { return m_sfd; } - - void Clear() - { - if (m_adb && m_sfd) - { - m_adb->DestroySFragmentDataRaw(m_sfd); - } - } - - SFragmentDataRAII& operator=(SFragmentDataRAII&& other) - { - if (!other.m_adb) return *this; - if (this != &other) - { - Clear(); - m_adb = other.m_adb; - m_sfd = other.m_sfd; - other.m_adb = nullptr; - other.m_sfd = nullptr; - } - return *this; - } - -private: - SFragmentDataRAII(const SFragmentDataRAII& other); - SFragmentDataRAII& operator=(const SFragmentDataRAII&); - - const IAnimationDatabase* m_adb; - SFragmentData* m_sfd; }; class IAnimationDatabaseManager diff --git a/Code/CryEngine/CryAction/ICryMannequinDefs.h b/Code/CryEngine/CryAction/ICryMannequinDefs.h index 7476a2ae1..b96088600 100644 --- a/Code/CryEngine/CryAction/ICryMannequinDefs.h +++ b/Code/CryEngine/CryAction/ICryMannequinDefs.h @@ -169,48 +169,47 @@ struct SCRCRef<1, THash> SCRCRef() : crc(INVALID) + , stringValue() { } explicit SCRCRef(const char* const nameString) : crc(INVALID) + , stringValue() { SetByString(nameString); } SCRCRef(const SCRCRef<1>& other) : crc(INVALID) + , stringValue() { - SetByString(other.stringValue); - } - - ~SCRCRef() - { - CleanUp(); + SetByString(other.c_str()); } SCRCRef<1>& operator=(const SCRCRef<1>& other) { if (&other != this) { - SetByString(other.stringValue); + SetByString(other.c_str()); } return *this; } - void CleanUp() - { - crc = INVALID; - } - void SetByString(const char* const nameString) { - CleanUp(); if (nameString && (nameString[0] != '\0')) { - stringValue = string(nameString); + const size_t lengthPlusOne = strlen(nameString) + 1; + stringValue.assign(nameString, nameString + lengthPlusOne); + crc = THash::CalculateHash(nameString); } + else + { + stringValue.clear(); + crc = INVALID; + } } ILINE bool IsEmpty() const @@ -220,7 +219,7 @@ struct SCRCRef<1, THash> ILINE const char* c_str() const { - return stringValue.c_str(); + return stringValue.empty() ? "" : stringValue.data(); } ILINE SCRCRef<1>& operator=(const char* const s) @@ -255,7 +254,7 @@ struct SCRCRef<1, THash> TInt crc; private: - string stringValue; + DynArray stringValue; }; typedef SCRCRef STagRef; diff --git a/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.cpp b/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.cpp index 8c8f2cdb5..96839979d 100644 --- a/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.cpp +++ b/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.cpp @@ -318,16 +318,6 @@ float AppendBlend(SFragmentData& outFragmentData, const SBlendQueryResult& blend return fragmentTime; } -SFragmentData* CAnimationDatabase::CreateSFragmentDataRaw() const -{ - return new SFragmentData; -} - -void CAnimationDatabase::DestroySFragmentDataRaw(SFragmentData* ptr) const -{ - delete ptr; -} - uint32 CAnimationDatabase::Query(SFragmentData& outFragmentData, const SBlendQuery& inBlendQuery, uint32 inOptionIdx, const IAnimationSet* inAnimSet, SFragmentSelection* outFragSelection) const { uint32 retFlags = 0; diff --git a/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.h b/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.h index d5d491fa2..a78583f32 100644 --- a/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.h +++ b/Code/CryEngine/CryAction/Mannequin/AnimationDatabase.h @@ -264,11 +264,6 @@ public: static void RegisterCVars(); -protected: - - virtual SFragmentData* CreateSFragmentDataRaw() const; - virtual void DestroySFragmentDataRaw(SFragmentData* ptr) const; - private: void EnumerateFragmentAnimAssets(const CFragment* pFragment, const IAnimationSet* animSet, SAnimAssetReport& assetReport, MannAssetCallback assetCallback, void* callbackContext) const; -- 2.11.4.GIT