Talk:Prop physics respawnable

From Valve Developer Community
Jump to navigation Jump to search

Is it possible to add these to your MODs? (to Respawn on trigger?) --JeffMOD 13:53, 9 Apr 2008 (PDT)

trigger_hurt crash

So tried tackling the trigger_hurt crash as my "hello world" exercise to sdk coding and came up with solution like this that works. I wonder if it's propper ?

The following code is in triggers.cpp line 845. The issue is that when HurtEntity is called the prop_physics_respawnable is destroyed inside it which also updates touchlinks and it causes the original loop to try accessing a freed touchlink causing a crash.

touchlink_t *root = ( touchlink_t * )GetDataObject( TOUCHLINK );
	if ( root )
	{
		for ( touchlink_t *link = root->nextLink; link != root; link = link->nextLink )
		{
			CBaseEntity *pTouch = link->entityTouched;
			if ( pTouch )
			{
				if ( HurtEntity( pTouch, fldmg ) )
				{
					hurtCount++;
				}
			}
		}
	}

Changed the code to this where I first gather all touched entities and then call HurtEntity on all of them

CUtlVector<CBaseEntity*> list;

	touchlink_t *root = ( touchlink_t * )GetDataObject( TOUCHLINK );
	if ( root )
	{
		for ( touchlink_t *link = root->nextLink; link != root; link = link->nextLink )
		{
			CBaseEntity *pTouch = link->entityTouched;
			if ( pTouch )
			{
				list.AddToTail(pTouch);
			}
		}
	}

	FOR_EACH_VEC(list, i) {
		CBaseEntity* pTouch = list[i];

		if (HurtEntity(pTouch, fldmg))
		{
			hurtCount++;
		}
	}

--Nescius (talk) 18:18, 14 March 2025 (PDT)