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 4 years ago committed by rarified
parent
commit
f30b909909
  1. 12
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp
  2. 2
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plResMgr/plKeyFinder.cpp
  3. 12
      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

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

@ -155,7 +155,7 @@ int main(int argc, char* argv[])
class plSoundBufferCollector : public plRegistryPageIterator, public plKeyCollector
{
public:
plSoundBufferCollector(hsTArray<plKey>& keyArray)
plSoundBufferCollector(std::set<plKey>& keyArray)
: plKeyCollector(keyArray) {}
hsBool EatPage(plRegistryPageNode* page)
@ -169,14 +169,14 @@ public:
bool DumpSounds()
{
hsTArray<plKey> soundKeys;
std::set<plKey> soundKeys;
plSoundBufferCollector soundCollector(soundKeys);
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)
{
// Ref it...
@ -207,7 +207,7 @@ bool DumpSounds()
}
}
soundKeys.Reset();
soundKeys.clear();
plIndirectUnloadIterator iter;
gResMgr->IterateAllPages(&iter);
@ -267,4 +267,4 @@ bool DumpStats(const char* patchDir)
plStatDumpIterator statDump(patchDir);
gResMgr->IterateAllPages(&statDump);
return true;
}
}

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

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

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

@ -42,18 +42,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plRegistryHelpers.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)
{
page->IterateKeys(this);
return true;
}
}

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
#include "hsTypes.h"
#include "hsTemplates.h"
#include "../pnKeyedObject/plKey.h"
#include <set>
class plKey;
class plRegistryPageNode;
@ -77,15 +77,19 @@ public:
//// 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
{
protected:
hsTArray<plKey> &fKeys;
std::set<plKey>& fKeys;
public:
plKeyCollector(hsTArray<plKey>& keys);
virtual hsBool EatKey(const plKey& key);
plKeyCollector(std::set<plKey>& keys) : fKeys(keys) { }
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

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

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

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

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

Loading…
Cancel
Save