Talk:Prop physics respawnable: Difference between revisions
Jump to navigation
Jump to search
(Trigger Respawn PP's in MOD) |
(→trigger_hurt crash: new section) |
||
Line 1: | Line 1: | ||
Is it possible to add these to your MODs? (to Respawn on trigger?) --[[User:JeffMOD|JeffMOD]] 13:53, 9 Apr 2008 (PDT) | Is it possible to add these to your MODs? (to Respawn on trigger?) --[[User:JeffMOD|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. | |||
<syntaxhighlight lang=cpp> | |||
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++; | |||
} | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
Changed the code to this where I first gather all touched entities and then call HurtEntity on all of them | |||
<syntaxhighlight lang=cpp> | |||
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++; | |||
} | |||
} | |||
</syntaxhighlight> | |||
--[[User:Nescius|Nescius]] ([[User talk:Nescius|talk]]) 18:18, 14 March 2025 (PDT) |
Latest revision as of 18:18, 14 March 2025
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++;
}
}