From 90275f777e836349936d00bb9d5bbaf08ad616fc Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 22 Feb 2017 06:41:25 +0200 Subject: [PATCH] [Client] Don't crash when dying while inside a container --- apps/openmw/mwmp/WorldController.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwmp/WorldController.cpp b/apps/openmw/mwmp/WorldController.cpp index 3596649f7..ffbb258ca 100644 --- a/apps/openmw/mwmp/WorldController.cpp +++ b/apps/openmw/mwmp/WorldController.cpp @@ -70,15 +70,20 @@ void mwmp::WorldController::closeContainer(const MWWorld::Ptr &container) { mwmp::Main::get().getLocalPlayer()->clearCurrentContainer(); - LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is closed.", - container.getCellRef().getRefId().c_str(), - container.getCellRef().getRefNum().mIndex); - - MWWorld::ContainerStore &cont = container.getClass().getContainerStore(container); - for (MWWorld::ContainerStoreIterator iter = cont.begin(); iter != cont.end(); iter++) + // If the player died while in a container, the container's Ptr could be invalid now + if (!container.isEmpty()) { - LOG_APPEND(Log::LOG_VERBOSE, " - Item. Refid: \"%s\" Count: %d", - iter->getCellRef().getRefId().c_str(), iter->getRefData().getCount()); + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is closed.", + container.getCellRef().getRefId().c_str(), + container.getCellRef().getRefNum().mIndex); + + MWWorld::ContainerStore &cont = container.getClass().getContainerStore(container); + for (MWWorld::ContainerStoreIterator iter = cont.begin(); iter != cont.end(); iter++) + { + LOG_APPEND(Log::LOG_VERBOSE, " - Item. Refid: \"%s\" Count: %d", + iter->getCellRef().getRefId().c_str(), iter->getRefData().getCount()); + } } + mwmp::Main::get().getLocalPlayer()->updateInventory(); }