- added NULL pointer checks to AActor::RemoveInventory to prevent items that destroy their owner in their use state from crashing the engine.

This commit is contained in:
Christoph Oelckers 2015-02-26 12:13:17 +01:00
parent 84f8c299ce
commit 13e98c301a

View file

@ -575,22 +575,25 @@ void AActor::AddInventory (AInventory *item)
//
//============================================================================
void AActor::RemoveInventory (AInventory *item)
void AActor::RemoveInventory(AInventory *item)
{
AInventory *inv, **invp;
if (item != NULL && item->Owner != NULL) // can happen if the owner was destroyed by some action from an item's use state.
{
invp = &item->Owner->Inventory;
for (inv = *invp; inv != NULL; invp = &inv->Inventory, inv = *invp)
{
if (inv == item)
{
*invp = item->Inventory;
item->DetachFromOwner ();
item->DetachFromOwner();
item->Owner = NULL;
item->Inventory = NULL;
break;
}
}
}
}
//============================================================================