- attempt to fix tomreyns segfault bug (mutex protection around cache)

This commit is contained in:
Mark Vejvoda 2011-09-24 22:17:48 +00:00
parent da57a589ba
commit 9268e3f5a7
2 changed files with 8 additions and 0 deletions

View File

@ -2112,7 +2112,9 @@ bool UnitUpdater::findCachedCellsEnemies(Vec2i center, int range, int size, vect
bool result = false;
//return result;
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > >::iterator iterFind = UnitRangeCellsLookupItemCache.find(center);
if(iterFind != UnitRangeCellsLookupItemCache.end()) {
std::map<int, std::map<int, UnitRangeCellsLookupItem > >::iterator iterFind3 = iterFind->second.find(size);
if(iterFind3 != iterFind->second.end()) {
@ -2129,6 +2131,7 @@ bool UnitUpdater::findCachedCellsEnemies(Vec2i center, int range, int size, vect
}
}
}
safeMutex.ReleaseLock();
return result;
}
@ -2231,6 +2234,8 @@ bool UnitUpdater::unitOnRange(const Unit *unit, int range, Unit **rangedPtr,
// Ok update our caches with the latest info
if(cacheItem.rangeCellList.size() > 0) {
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
//cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++;
UnitRangeCellsLookupItemCache[center][size][range] = cacheItem;
}
@ -2413,6 +2418,8 @@ vector<Unit*> UnitUpdater::enemyUnitsOnRange(const Unit *unit,const AttackSkillT
// Ok update our caches with the latest info
if(cacheItem.rangeCellList.size() > 0) {
MutexSafeWrapper safeMutex(&mutexUnitRangeCellsLookupItemCache,string(__FILE__) + "_" + intToStr(__LINE__));
//cacheItem.UnitRangeCellsLookupItemCacheTimerCountIndex = UnitRangeCellsLookupItemCacheTimerCount++;
UnitRangeCellsLookupItemCache[center][size][range] = cacheItem;
}

View File

@ -80,6 +80,7 @@ private:
float attackWarnRange;
AttackWarnings attackWarnings;
Mutex mutexUnitRangeCellsLookupItemCache;
std::map<Vec2i, std::map<int, std::map<int, UnitRangeCellsLookupItem > > > UnitRangeCellsLookupItemCache;
//std::map<int,ExploredCellsLookupKey> ExploredCellsLookupItemCacheTimer;
//int UnitRangeCellsLookupItemCacheTimerCount;