1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-04-01 17:36:41 +00:00

[Client] Avoid crashes by only using inventory listeners in loaded cells

Previously, receiving a Container packet about an actor with a previously initialized listener who was currently located in an unloaded cell crashed the game.
This commit is contained in:
David Cernat 2019-12-02 09:37:10 +02:00
parent a54bc364ba
commit 385ef55848
2 changed files with 33 additions and 11 deletions

View file

@ -380,11 +380,10 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr
/* /*
Start of tes3mp change (major) Start of tes3mp change (major)
Disable the listener here because it keeps causing crashes; this should only be Only fire inventory events for actors in loaded cells to avoid crashes
a temporary solution
*/ */
//if (mListener && !actorPtr.getClass().hasInventoryStore(actorPtr)) if (mListener && !actorPtr.getClass().hasInventoryStore(actorPtr) && MWBase::Environment::get().getWorld()->isCellActive(*actorPtr.getCell()->getCell()))
// mListener->itemAdded(item, count); mListener->itemAdded(item, count);
/* /*
End of tes3mp change (major) End of tes3mp change (major)
*/ */
@ -569,11 +568,10 @@ int MWWorld::ContainerStore::remove(const Ptr& item, int count, const Ptr& actor
/* /*
Start of tes3mp change (major) Start of tes3mp change (major)
Disable the listener here because it keeps causing crashes; this should only be Only fire inventory events for actors in loaded cells to avoid crashes
a temporary solution
*/ */
//if (mListener && !actor.getClass().hasInventoryStore(actor)) if (mListener && !actor.getClass().hasInventoryStore(actor) && MWBase::Environment::get().getWorld()->isCellActive(*actor.getCell()->getCell()))
// mListener->itemRemoved(item, count - toRemove); mListener->itemRemoved(item, count - toRemove);
/* /*
End of tes3mp change (major) End of tes3mp change (major)
*/ */

View file

@ -156,8 +156,16 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr,
autoEquip(actorPtr); autoEquip(actorPtr);
} }
if (mListener) /*
Start of tes3mp change (major)
Only fire inventory events for actors in loaded cells to avoid crashes
*/
if (mListener && MWBase::Environment::get().getWorld()->isCellActive(*actorPtr.getCell()->getCell()))
mListener->itemAdded(*retVal, count); mListener->itemAdded(*retVal, count);
/*
End of tes3mp change (major)
*/
return retVal; return retVal;
} }
@ -810,8 +818,16 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
mSelectedEnchantItem = end(); mSelectedEnchantItem = end();
} }
if (mListener) /*
Start of tes3mp change (major)
Only fire inventory events for actors in loaded cells to avoid crashes
*/
if (mListener && MWBase::Environment::get().getWorld()->isCellActive(*actor.getCell()->getCell()))
mListener->itemRemoved(item, retCount); mListener->itemRemoved(item, retCount);
/*
End of tes3mp change (major)
*/
return retCount; return retCount;
} }
@ -911,8 +927,16 @@ void MWWorld::InventoryStore::fireEquipmentChangedEvent(const Ptr& actor)
{ {
if (!mUpdatesEnabled) if (!mUpdatesEnabled)
return; return;
if (mInventoryListener) /*
Start of tes3mp change (major)
Only fire inventory events for actors in loaded cells to avoid crashes
*/
if (mInventoryListener && MWBase::Environment::get().getWorld()->isCellActive(*actor.getCell()->getCell()))
mInventoryListener->equipmentChanged(); mInventoryListener->equipmentChanged();
/*
End of tes3mp change (major)
*/
// if player, update inventory window // if player, update inventory window
/* /*