From 92775824e63f5887e373b0f14fd1b36336612f47 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Thu, 29 Feb 2024 06:52:48 +0700 Subject: [PATCH] IsWalkableTraceLineClear: Fixed deadlock (mutual collisions in traces leading to hang) --- regamedll/game_shared/bot/nav.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/regamedll/game_shared/bot/nav.h b/regamedll/game_shared/bot/nav.h index 6f994dd7..a917aa99 100644 --- a/regamedll/game_shared/bot/nav.h +++ b/regamedll/game_shared/bot/nav.h @@ -388,15 +388,21 @@ inline bool IsWalkableTraceLineClear(Vector &from, Vector &to, unsigned int flag { TraceResult result; edict_t *pEntIgnore = nullptr; + edict_t *pEntPrev = nullptr; Vector useFrom = from; - while (true) + const int maxTries = 50; + for (int t = 0; t < maxTries; ++t) { UTIL_TraceLine(useFrom, to, ignore_monsters, pEntIgnore, &result); // if we hit a walkable entity, try again if (result.flFraction != 1.0f && (result.pHit && IsEntityWalkable(VARS(result.pHit), flags))) { + if (result.pHit == pEntPrev) + return false; // deadlock, give up + + pEntPrev = pEntIgnore; pEntIgnore = result.pHit; // start from just beyond where we hit to avoid infinite loops