Fixed crash sometimes occurring while zbot map analyzing (#844)

This commit is contained in:
Dmitry Novikov 2023-09-05 10:53:05 +07:00 committed by GitHub
parent facc2be534
commit e8bff71475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 27 deletions

View File

@ -42,9 +42,6 @@ enum
BOT_PROGGRESS_HIDE, // hide status bar progress BOT_PROGGRESS_HIDE, // hide status bar progress
}; };
extern int _navAreaCount;
extern int _currentIndex;
class CCSBot; class CCSBot;
class BotChatterInterface; class BotChatterInterface;
@ -970,7 +967,6 @@ private:
const CNavNode *m_navNodeList; const CNavNode *m_navNodeList;
CNavNode *m_currentNode; CNavNode *m_currentNode;
NavDirType m_generationDir; NavDirType m_generationDir;
NavAreaList::iterator m_analyzeIter;
enum ProcessType enum ProcessType
{ {

View File

@ -30,8 +30,7 @@
const float updateTimesliceDuration = 0.5f; const float updateTimesliceDuration = 0.5f;
int _navAreaCount = 0; unsigned int _generationIndex = 0; // used for iterating nav areas during generation process
int _currentIndex = 0;
inline CNavNode *LadderEndSearch(CBaseEntity *pEntity, const Vector *pos, NavDirType mountDir) inline CNavNode *LadderEndSearch(CBaseEntity *pEntity, const Vector *pos, NavDirType mountDir)
{ {
@ -385,11 +384,8 @@ void CCSBot::UpdateLearnProcess()
void CCSBot::StartAnalyzeAlphaProcess() void CCSBot::StartAnalyzeAlphaProcess()
{ {
m_processMode = PROCESS_ANALYZE_ALPHA; m_processMode = PROCESS_ANALYZE_ALPHA;
m_analyzeIter = TheNavAreaList.begin(); _generationIndex = 0;
_navAreaCount = TheNavAreaList.size();
_currentIndex = 0;
ApproachAreaAnalysisPrep(); ApproachAreaAnalysisPrep();
DestroyHidingSpots(); DestroyHidingSpots();
@ -400,15 +396,18 @@ void CCSBot::StartAnalyzeAlphaProcess()
bool CCSBot::AnalyzeAlphaStep() bool CCSBot::AnalyzeAlphaStep()
{ {
_currentIndex++; _generationIndex++;
if (m_analyzeIter == TheNavAreaList.end())
if (_generationIndex < 0 || _generationIndex >= TheNavAreaList.size())
return false; return false;
CNavArea *area = (*m_analyzeIter); // TODO: Pretty ugly and very slow way to access element by index
// There is no reason not to use a vector instead of a linked list
const NavAreaList::const_iterator &iter = std::next(TheNavAreaList.begin(), _generationIndex - 1);
CNavArea *area = (*iter);
area->ComputeHidingSpots(); area->ComputeHidingSpots();
area->ComputeApproachAreas(); area->ComputeApproachAreas();
m_analyzeIter++;
return true; return true;
} }
@ -426,29 +425,30 @@ void CCSBot::UpdateAnalyzeAlphaProcess()
} }
} }
float progress = (double(_currentIndex) / double(_navAreaCount)) * 0.5f; float progress = (double(_generationIndex) / double(TheNavAreaList.size())) * 0.5f;
drawProgressMeter(progress, "#CZero_AnalyzingHidingSpots"); drawProgressMeter(progress, "#CZero_AnalyzingHidingSpots");
} }
void CCSBot::StartAnalyzeBetaProcess() void CCSBot::StartAnalyzeBetaProcess()
{ {
m_processMode = PROCESS_ANALYZE_BETA; m_processMode = PROCESS_ANALYZE_BETA;
m_analyzeIter = TheNavAreaList.begin(); _generationIndex = 0;
_navAreaCount = TheNavAreaList.size();
_currentIndex = 0;
} }
bool CCSBot::AnalyzeBetaStep() bool CCSBot::AnalyzeBetaStep()
{ {
_currentIndex++; _generationIndex++;
if (m_analyzeIter == TheNavAreaList.end())
if (_generationIndex < 0 || _generationIndex >= TheNavAreaList.size())
return false; return false;
CNavArea *area = (*m_analyzeIter); // TODO: Pretty ugly and very slow way to access element by index
// There is no reason not to use a vector instead of a linked list
const NavAreaList::const_iterator &iter = std::next(TheNavAreaList.begin(), _generationIndex - 1);
CNavArea *area = (*iter);
area->ComputeSpotEncounters(); area->ComputeSpotEncounters();
area->ComputeSniperSpots(); area->ComputeSniperSpots();
m_analyzeIter++;
return true; return true;
} }
@ -466,7 +466,7 @@ void CCSBot::UpdateAnalyzeBetaProcess()
} }
} }
float progress = (double(_currentIndex) / double(_navAreaCount) + 1.0f) * 0.5f; float progress = (double(_generationIndex) / double(TheNavAreaList.size()) + 1.0f) * 0.5f;
drawProgressMeter(progress, "#CZero_AnalyzingApproachPoints"); drawProgressMeter(progress, "#CZero_AnalyzingApproachPoints");
} }