Browse Source

Fix a bug related to trashed keys. (cherry picked from H'uru e2b5786988)

It appears that the hsTArray memory management really sucks for smart
pointers like plKey. The crash mentioned at
http://forum.guildofwriters.org/viewtopic.php?f=117&t=6291 went away
immediately after switching plKeyCollector to an std::set.
hoikas/keycollector-1
Adam Johnson 5 years ago committed by rarified
parent
commit
f30b909909
  1. 10
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp
  2. 2
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp
  3. 10
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plRegistryHelpers.cpp
  4. 14
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plRegistryHelpers.h
  5. 7
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
  6. 3
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plResManagerHelper.h

10
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp

@ -155,7 +155,7 @@ int main(int argc, char* argv[])
class plSoundBufferCollector : public plRegistryPageIterator, public plKeyCollector class plSoundBufferCollector : public plRegistryPageIterator, public plKeyCollector
{ {
public: public:
plSoundBufferCollector(hsTArray<plKey>& keyArray) plSoundBufferCollector(std::set<plKey>& keyArray)
: plKeyCollector(keyArray) {} : plKeyCollector(keyArray) {}
hsBool EatPage(plRegistryPageNode* page) hsBool EatPage(plRegistryPageNode* page)
@ -169,14 +169,14 @@ public:
bool DumpSounds() bool DumpSounds()
{ {
hsTArray<plKey> soundKeys; std::set<plKey> soundKeys;
plSoundBufferCollector soundCollector(soundKeys); plSoundBufferCollector soundCollector(soundKeys);
gResMgr->IterateAllPages(&soundCollector); gResMgr->IterateAllPages(&soundCollector);
for (int i = 0; i < soundKeys.GetCount(); i++) for (std::set<plKey>::iterator it = soundKeys.begin(); it != soundKeys.end(); ++it)
{ {
plSoundBuffer* buffer = plSoundBuffer::ConvertNoRef(soundKeys[i]->VerifyLoaded()); plSoundBuffer* buffer = plSoundBuffer::ConvertNoRef((*it)->VerifyLoaded());
if (buffer) if (buffer)
{ {
// Ref it... // Ref it...
@ -207,7 +207,7 @@ bool DumpSounds()
} }
} }
soundKeys.Reset(); soundKeys.clear();
plIndirectUnloadIterator iter; plIndirectUnloadIterator iter;
gResMgr->IterateAllPages(&iter); gResMgr->IterateAllPages(&iter);

2
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp

@ -168,7 +168,7 @@ public:
if( stricmp( pageNode->GetPageInfo().GetAge(), fAgeName ) == 0 ) if( stricmp( pageNode->GetPageInfo().GetAge(), fAgeName ) == 0 )
{ {
// Try loading and searching thru this page // Try loading and searching thru this page
hsTArray<plKey> keyRefs; std::set<plKey> keyRefs;
IGetResMgr()->LoadPageKeys( pageNode ); IGetResMgr()->LoadPageKeys( pageNode );
plKeyCollector coll( keyRefs ); plKeyCollector coll( keyRefs );

10
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plRegistryHelpers.cpp

@ -42,16 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plRegistryHelpers.h" #include "plRegistryHelpers.h"
#include "plRegistryNode.h" #include "plRegistryNode.h"
plKeyCollector::plKeyCollector( hsTArray<plKey> &keys ) : fKeys( keys )
{
}
hsBool plKeyCollector::EatKey(const plKey& key)
{
fKeys.Append(key);
return true;
}
hsBool plIndirectUnloadIterator::EatPage(plRegistryPageNode* page) hsBool plIndirectUnloadIterator::EatPage(plRegistryPageNode* page)
{ {
page->IterateKeys(this); page->IterateKeys(this);

14
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plRegistryHelpers.h

@ -53,8 +53,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plRegistryHelpers_h #define _plRegistryHelpers_h
#include "hsTypes.h" #include "hsTypes.h"
#include "hsTemplates.h"
#include "../pnKeyedObject/plKey.h" #include "../pnKeyedObject/plKey.h"
#include <set>
class plKey; class plKey;
class plRegistryPageNode; class plRegistryPageNode;
@ -77,15 +77,19 @@ public:
//// plKeyCollector ////////////////////////////////////////////////////////// //// plKeyCollector //////////////////////////////////////////////////////////
// Helper key iterator that collects the given keys into the given hsTArray // Helper key iterator that collects keys into an std::set
class plKeyCollector : public plRegistryKeyIterator class plKeyCollector : public plRegistryKeyIterator
{ {
protected: protected:
hsTArray<plKey> &fKeys; std::set<plKey>& fKeys;
public: public:
plKeyCollector(hsTArray<plKey>& keys); plKeyCollector(std::set<plKey>& keys) : fKeys(keys) { }
virtual hsBool EatKey(const plKey& key); virtual hsBool EatKey(const plKey& key)
{
fKeys.insert(key);
return true;
}
}; };
// If you loaded keys with another iterator, this will ensure that they're unloaded // If you loaded keys with another iterator, this will ensure that they're unloaded

7
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp

@ -1016,12 +1016,11 @@ void plResManager::SetProgressBarProc(plProgressProc proc)
class plResAgeHolder : public hsRefCnt class plResAgeHolder : public hsRefCnt
{ {
public: public:
hsTArray<plKey> fKeys; std::set<plKey> fKeys;
std::string fAge; std::string fAge;
plResAgeHolder() {} plResAgeHolder() {}
plResAgeHolder( const char* age ) : fAge( age ) {} plResAgeHolder( const char* age ) : fAge( age ) {}
~plResAgeHolder() { fKeys.Reset(); }
}; };
//// plResHolderIterator ///////////////////////////////////////////////////// //// plResHolderIterator /////////////////////////////////////////////////////
@ -1029,12 +1028,12 @@ class plResAgeHolder : public hsRefCnt
class plResHolderIterator : public plRegistryPageIterator class plResHolderIterator : public plRegistryPageIterator
{ {
protected: protected:
hsTArray<plKey>& fKeys; std::set<plKey>& fKeys;
const char* fAgeName; const char* fAgeName;
plResManager* fResMgr; plResManager* fResMgr;
public: public:
plResHolderIterator(const char* age, hsTArray<plKey>& keys, plResManager* resMgr) plResHolderIterator(const char* age, std::set<plKey>& keys, plResManager* resMgr)
: fAgeName(age), fKeys(keys), fResMgr(resMgr) {} : fAgeName(age), fKeys(keys), fResMgr(resMgr) {}
virtual hsBool EatPage(plRegistryPageNode* page) virtual hsBool EatPage(plRegistryPageNode* page)

3
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plResManagerHelper.h

@ -135,12 +135,11 @@ class plResPageKeyRefList : public plKeyCollector
{ {
protected: protected:
hsTArray<plKey> fKeyList; std::set<plKey> fKeyList;
public: public:
plResPageKeyRefList() : plKeyCollector( fKeyList ) {} plResPageKeyRefList() : plKeyCollector( fKeyList ) {}
virtual ~plResPageKeyRefList() { fKeyList.Reset(); }
}; };
#endif // _plResManagerHelper_h #endif // _plResManagerHelper_h

Loading…
Cancel
Save