- Fixed issues and memory leaks related to decks unlocking

- Fixed an issue where a GameObserver could be null for some mana costs associated to a targetChooser
This commit is contained in:
wagic.the.homebrew
2011-10-22 13:38:43 +00:00
parent 91e9881903
commit 4c42636bd5
4 changed files with 64 additions and 3 deletions
+1
View File
@@ -28,6 +28,7 @@ public:
vector<DeckMetaData*> * getAIDeckOrderList(); vector<DeckMetaData*> * getAIDeckOrderList();
void AddMetaData( const std::string& filename, bool isAI); void AddMetaData( const std::string& filename, bool isAI);
void DeleteMetaData( const std::string& filename, bool isAI);
DeckMetaData* getDeckMetaDataById(int deckId, bool isAI); DeckMetaData* getDeckMetaDataById(int deckId, bool isAI);
DeckMetaData* getDeckMetaDataByFilename(const std::string& filename, bool isAI); DeckMetaData* getDeckMetaDataByFilename(const std::string& filename, bool isAI);
StatsWrapper* getExtendedStatsForDeckId(int deckId, MTGAllCards* collection, bool isAI); StatsWrapper* getExtendedStatsForDeckId(int deckId, MTGAllCards* collection, bool isAI);
+46
View File
@@ -119,6 +119,52 @@ void DeckManager::AddMetaData( const string& filename, bool isAI )
} }
} }
void DeckManager::DeleteMetaData( const string& filename, bool isAI )
{
map<string, StatsWrapper *>::iterator it;
vector<DeckMetaData *>::iterator metaDataIter;
if (isAI)
{
it = aiDeckStatsMap.find(filename);
if (it != aiDeckStatsMap.end())
{
SAFE_DELETE(it->second);
aiDeckStatsMap.erase(it);
}
for( metaDataIter = mInstance->aiDeckOrderList.begin(); metaDataIter != mInstance->aiDeckOrderList.end(); ++metaDataIter)
{
if ((*metaDataIter)->getFilename() == filename)
{
SAFE_DELETE( *metaDataIter );
aiDeckOrderList.erase(metaDataIter);
break;
}
}
}
else
{
it = playerDeckStatsMap.find(filename);
if (it != playerDeckStatsMap.end())
{
SAFE_DELETE(it->second);
playerDeckStatsMap.erase(it);
}
for( metaDataIter = mInstance->playerDeckOrderList.begin(); metaDataIter != mInstance->playerDeckOrderList.end(); ++metaDataIter)
{
if ((*metaDataIter)->getFilename() == filename)
{
SAFE_DELETE( *metaDataIter );
playerDeckOrderList.erase(metaDataIter);
break;
}
}
}
}
StatsWrapper * DeckManager::getExtendedStatsForDeckId( int deckId, MTGAllCards *collection, bool isAI ) StatsWrapper * DeckManager::getExtendedStatsForDeckId( int deckId, MTGAllCards *collection, bool isAI )
{ {
DeckMetaData *selectedDeck = getDeckMetaDataById( deckId, isAI ); DeckMetaData *selectedDeck = getDeckMetaDataById( deckId, isAI );
+10 -3
View File
@@ -51,6 +51,7 @@ vector<DeckMetaData *> GameState::BuildDeckList(const string& path, const string
if (meta) if (meta)
{ {
found = 1;
//Check if the deck is unlocked based on sets etc... //Check if the deck is unlocked based on sets etc...
bool unlocked = true; bool unlocked = true;
vector<int> unlockRequirements = meta->getUnlockRequirements(); vector<int> unlockRequirements = meta->getUnlockRequirements();
@@ -65,7 +66,6 @@ vector<DeckMetaData *> GameState::BuildDeckList(const string& path, const string
if (unlocked) if (unlocked)
{ {
found = 1;
if (statsPlayer) if (statsPlayer)
{ {
std::ostringstream aiStatsDeckName; std::ostringstream aiStatsDeckName;
@@ -85,10 +85,17 @@ vector<DeckMetaData *> GameState::BuildDeckList(const string& path, const string
meta->mStatsFilename = options.profileFile(playerStatsDeckName.str()); meta->mStatsFilename = options.profileFile(playerStatsDeckName.str());
meta->mIsAI = false; meta->mIsAI = false;
} }
retList.push_back(meta); retList.push_back(meta);
nbDecks++;
} }
else
{
//updateMetaDataList in DeckManager.cpp performs some weird magic, swapping data between its cache and the "retList" from this function
//Bottom line, we need to guarantee retList contains exactly the same items as (or updated versions of) the items in DeckManager Cache
//In other words, any meta data that didn't make it to retList in this function must be erased from the DeckManager cache
deckManager->DeleteMetaData(filename.str(), isAI);
}
nbDecks++;
} }
meta = NULL; meta = NULL;
} }
+7
View File
@@ -826,6 +826,13 @@ bool TargetChooser::validTargetsExist(int maxTargets)
int TargetChooser::countValidTargets() int TargetChooser::countValidTargets()
{ {
int result = 0; int result = 0;
//Some TargetChooser objects are created at a point where no observer is available
// see ManaCost::parseManaCost which sets observer to NULL in some cases (namely: when the cards database is loaded at game start)
// This is a workaround for this situation
if (!observer && source)
observer = source->getObserver();
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i)
{ {
assert(observer); assert(observer);