[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.
pull/556/head
David Cernat 5 years ago
parent a54bc364ba
commit 385ef55848

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

@ -156,8 +156,16 @@ MWWorld::ContainerStoreIterator MWWorld::InventoryStore::add(const Ptr& itemPtr,
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);
/*
End of tes3mp change (major)
*/
return retVal;
}
@ -810,8 +818,16 @@ int MWWorld::InventoryStore::remove(const Ptr& item, int count, const Ptr& actor
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);
/*
End of tes3mp change (major)
*/
return retCount;
}
@ -911,8 +927,16 @@ void MWWorld::InventoryStore::fireEquipmentChangedEvent(const Ptr& actor)
{
if (!mUpdatesEnabled)
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();
/*
End of tes3mp change (major)
*/
// if player, update inventory window
/*

Loading…
Cancel
Save