Fixed CBotClass::FreeLock crash on some compilers

dev-time-step
krzys-h 2016-01-23 21:33:58 +01:00
parent 9bece23ede
commit 84521ef08a
2 changed files with 7 additions and 2 deletions

View File

@ -148,7 +148,12 @@ void CBotClass::FreeLock(CBotProgram* prog)
pClass->m_lockCurrentCount = 0; pClass->m_lockCurrentCount = 0;
} }
pClass->m_lockProg.erase(std::remove(pClass->m_lockProg.begin(), pClass->m_lockProg.end(), prog)); // Note: erasing an end iterator is undefined behaviour
auto it = std::remove(pClass->m_lockProg.begin(), pClass->m_lockProg.end(), prog);
if (it != pClass->m_lockProg.end())
{
pClass->m_lockProg.erase(it);
}
} }
} }

View File

@ -387,7 +387,7 @@ private:
//! How many times the program currently holding the lock called Lock() //! How many times the program currently holding the lock called Lock()
int m_lockCurrentCount = 0; int m_lockCurrentCount = 0;
//! Programs waiting for lock //! Programs waiting for lock. m_lockProg[0] is the program currently holding the lock, if any
std::deque<CBotProgram*> m_lockProg{}; std::deque<CBotProgram*> m_lockProg{};
}; };