ncItem: unset m_nextItem and owner fields in OnRemoveEntity, exit out of PreFrame when freed

This commit is contained in:
Marco Cawthorne 2025-02-09 01:17:16 -08:00
parent e60556e124
commit 143e247cf3
2 changed files with 11 additions and 3 deletions

View file

@ -118,6 +118,8 @@ public:
virtual bool IsWeapon(void);
virtual bool InInventory(void);
virtual void OnRemoveEntity(void);
private:
/** Called to signal that the owner added this weapon to their inventory. */
virtual void _AddedCallback(void);

View file

@ -607,7 +607,7 @@ ncItem::PredictPreFrame(void)
m_nextItem = (ncItem)findentity(world, ::entnum, chain_entnum);
if (wasfreed(m_nextItem)) {
m_nextItem = __NULL__;
return;
}
if (owner == __NULL__ && owner_entnum) {
@ -617,8 +617,8 @@ ncItem::PredictPreFrame(void)
_AddedCallback();
/* we may have been removed in _AddedCallback */
if (wasfreed(this)) {
owner = __NULL__;
if (this && wasfreed(this)) {
return;
}
}
}
@ -657,6 +657,12 @@ ncItem::PredictPostFrame(void)
}
#endif
void
ncItem::OnRemoveEntity(void)
{
m_nextItem = owner = 0;
}
void
ncItem::AddedToInventory(void)
{