[Client] Fix potential invalid pointer when storing cell unloads

Notably, builds of the client done with Clang were crashing on startup before this.
0.6.3
David Cernat 7 years ago
parent 420dab10e1
commit ce11a1dfa9

@ -1544,7 +1544,7 @@ void LocalPlayer::clearCurrentContainer()
currentContainer.mpNum = 0; currentContainer.mpNum = 0;
} }
void LocalPlayer::storeCellState(ESM::Cell cell, int stateType) void LocalPlayer::storeCellState(const ESM::Cell& cell, int stateType)
{ {
std::vector<CellState>::iterator iter; std::vector<CellState>::iterator iter;

@ -91,7 +91,7 @@ namespace mwmp
void clearCellStates(); void clearCellStates();
void clearCurrentContainer(); void clearCurrentContainer();
void storeCellState(ESM::Cell cell, int stateType); void storeCellState(const ESM::Cell& cell, int stateType);
void storeCurrentContainer(const MWWorld::Ptr& container); void storeCurrentContainer(const MWWorld::Ptr& container);
void playAnimation(); void playAnimation();

@ -243,6 +243,17 @@ namespace MWWorld
std::cout << "Unloading cell\n"; std::cout << "Unloading cell\n";
ListAndResetObjectsVisitor visitor; ListAndResetObjectsVisitor visitor;
/*
Start of tes3mp addition
Set a const pointer to the iterator's ESM::Cell here, because
(*iter)->getCell() can become invalid later down
*/
const ESM::Cell* cell = (*iter)->getCell();
/*
End of tes3mp addition
*/
(*iter)->forEach<ListAndResetObjectsVisitor>(visitor); (*iter)->forEach<ListAndResetObjectsVisitor>(visitor);
for (std::vector<MWWorld::Ptr>::const_iterator iter2 (visitor.mObjects.begin()); for (std::vector<MWWorld::Ptr>::const_iterator iter2 (visitor.mObjects.begin());
iter2!=visitor.mObjects.end(); ++iter2) iter2!=visitor.mObjects.end(); ++iter2)
@ -276,7 +287,7 @@ namespace MWWorld
Store a cell unload for the LocalPlayer Store a cell unload for the LocalPlayer
*/ */
mwmp::Main::get().getLocalPlayer()->storeCellState(*(*iter)->getCell(), mwmp::CellState::UNLOAD); mwmp::Main::get().getLocalPlayer()->storeCellState(*cell, mwmp::CellState::UNLOAD);
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

Loading…
Cancel
Save