fix rare crash in containers

This commit is contained in:
Eduardo Bart 2012-04-05 17:51:06 -03:00
parent 4f15da695c
commit 248ea9e8bc
1 changed files with 7 additions and 11 deletions

View File

@ -49,8 +49,11 @@ void Game::resetGameStates()
m_followingCreature = nullptr; m_followingCreature = nullptr;
m_attackingCreature = nullptr; m_attackingCreature = nullptr;
for(auto& it : m_containers) for(auto& it : m_containers) {
(it.second)->close(); const ContainerPtr& container = it.second;
if(container)
container->close();
}
m_containers.clear(); m_containers.clear();
m_worldName = ""; m_worldName = "";
@ -196,14 +199,7 @@ void Game::processCloseContainer(int containerId)
return; return;
} }
auto it = m_containers.find(container->getId()); m_containers[containerId] = nullptr;
if(it == m_containers.end() || it->second != container) {
logTraceError("invalid container");
return;
}
m_containers.erase(it);
container->close(); container->close();
} }
@ -598,7 +594,7 @@ void Game::open(const ItemPtr& item, const ContainerPtr& previousContainer)
int id = 0; int id = 0;
if(!previousContainer) { if(!previousContainer) {
// find a free container id // find a free container id
while(m_containers.find(id) != m_containers.end()) while(m_containers[id] != nullptr)
id++; id++;
} else { } else {
id = previousContainer->getId(); id = previousContainer->getId();