From 9268e3f5a7c2c42b1493692f0d0cde2f77f74b2a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 24 Sep 2011 22:17:48 +0000 Subject: [PATCH] - attempt to fix tomreyns segfault bug (mutex protection around cache) --- source/glest_game/world/unit_updater.cpp | 7 +++++++ source/glest_game/world/unit_updater.h | 1 + 2 files changed, 8 insertions(+) diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index c706c10c..a5b6fa47 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -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 > >::iterator iterFind = UnitRangeCellsLookupItemCache.find(center); + if(iterFind != UnitRangeCellsLookupItemCache.end()) { std::map >::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 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; } diff --git a/source/glest_game/world/unit_updater.h b/source/glest_game/world/unit_updater.h index c5557ae8..5fe80950 100644 --- a/source/glest_game/world/unit_updater.h +++ b/source/glest_game/world/unit_updater.h @@ -80,6 +80,7 @@ private: float attackWarnRange; AttackWarnings attackWarnings; + Mutex mutexUnitRangeCellsLookupItemCache; std::map > > UnitRangeCellsLookupItemCache; //std::map ExploredCellsLookupItemCacheTimer; //int UnitRangeCellsLookupItemCacheTimerCount;