Skip to content

Commit

Permalink
Prevent crash when caller triggered itself lot of times.
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Dec 8, 2017
1 parent 519a731 commit adeb09a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions regamedll/dlls/subs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ NOINLINE void CBaseEntity::SUB_UseTargets(CBaseEntity *pActivator, USE_TYPE useT
}
}

int g_iTargetRecursionLevel = 0;

void FireTargets(const char *targetName, CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
{
edict_t *pentTarget = nullptr;
Expand All @@ -126,6 +128,24 @@ void FireTargets(const char *targetName, CBaseEntity *pActivator, CBaseEntity *p
#ifdef REGAMEDLL_FIXES
if (targetName[0] == '\0')
return;

const int MAX_TARGET_RECURSION_LEVEL = 128;
if (pCaller)
{
if (FStrEq(pCaller->pev->targetname, targetName))
{
if (g_iTargetRecursionLevel++ > MAX_TARGET_RECURSION_LEVEL)
{
ALERT(at_warning, "Warning: %s \"%s\" triggered itself over %i times.\n", pCaller->pev->classname.str(), pCaller->pev->targetname.str(), MAX_TARGET_RECURSION_LEVEL);
g_iTargetRecursionLevel = 0;
return;
}
}
}
else
{
g_iTargetRecursionLevel = 0;
}
#endif

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

0 comments on commit adeb09a

Please sign in to comment.