Skip to content

Commit adeb09a

Browse files
committed
Prevent crash when caller triggered itself lot of times.
1 parent 519a731 commit adeb09a

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

regamedll/dlls/subs.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ NOINLINE void CBaseEntity::SUB_UseTargets(CBaseEntity *pActivator, USE_TYPE useT
117117
}
118118
}
119119

120+
int g_iTargetRecursionLevel = 0;
121+
120122
void FireTargets(const char *targetName, CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
121123
{
122124
edict_t *pentTarget = nullptr;
@@ -126,6 +128,24 @@ void FireTargets(const char *targetName, CBaseEntity *pActivator, CBaseEntity *p
126128
#ifdef REGAMEDLL_FIXES
127129
if (targetName[0] == '\0')
128130
return;
131+
132+
const int MAX_TARGET_RECURSION_LEVEL = 128;
133+
if (pCaller)
134+
{
135+
if (FStrEq(pCaller->pev->targetname, targetName))
136+
{
137+
if (g_iTargetRecursionLevel++ > MAX_TARGET_RECURSION_LEVEL)
138+
{
139+
ALERT(at_warning, "Warning: %s \"%s\" triggered itself over %i times.\n", pCaller->pev->classname.str(), pCaller->pev->targetname.str(), MAX_TARGET_RECURSION_LEVEL);
140+
g_iTargetRecursionLevel = 0;
141+
return;
142+
}
143+
}
144+
}
145+
else
146+
{
147+
g_iTargetRecursionLevel = 0;
148+
}
129149
#endif
130150

131151
ALERT(at_aiconsole, "Firing: (%s)\n", targetName);
@@ -142,6 +162,7 @@ void FireTargets(const char *targetName, CBaseEntity *pActivator, CBaseEntity *p
142162
{
143163
ALERT(at_aiconsole, "Found: %s, firing (%s)\n", STRING(pTarget->pev->classname), targetName);
144164
pTarget->Use(pActivator, pCaller, useType, value);
165+
g_iTargetRecursionLevel = 0;
145166
}
146167
}
147168
}

0 commit comments

Comments
 (0)