diff --git a/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp b/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp index a655d1d89a..d788bb41c9 100644 --- a/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp +++ b/dep/recastnavigation/Detour/Source/DetourNavMesh.cpp @@ -670,6 +670,11 @@ namespace } } + // A polygon whose detail mesh has no qualifying edge (no triangles, or none with a boundary flag in the boundary-only pass) leaves + // pmin/pmax unset; the caller has already put the position into `closest`, so keep that instead of reading through null. + if (!pmin || !pmax) + return; + dtVlerp(closest, pmin, pmax, tmin); } } diff --git a/src/server/game/Maps/MapUpdater.cpp b/src/server/game/Maps/MapUpdater.cpp index d8e6578d98..c3b0ee23df 100644 --- a/src/server/game/Maps/MapUpdater.cpp +++ b/src/server/game/Maps/MapUpdater.cpp @@ -20,6 +20,7 @@ #include "Log.h" #include "Map.h" #include "Metric.h" +#include "PathGenerator.h" #include #include #include @@ -95,6 +96,8 @@ unsigned int SehSafeMapUpdate(Map* m, uint32 diff, SehFault* fault) noexcept // that pointed at session teardown instead of the aura bug.) __except (SehFilter(GetExceptionInformation(), fault)) { + // The unwind skips destructors below the fault: a nav lock held by the faulting pathfind would stay locked for good. + ReleaseNavLockAfterFault(); return fault->code; } } diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index d59239a3ff..5c601e6dea 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -56,6 +56,32 @@ namespace static std::array locks; return locks[mapId % kNavExecLockStripes]; } + + // The nav lock this thread holds, if any. MapUpdater catches a hardware fault (SEH) in Map::Update and skips the tick; that unwind + // does not run the destructor of a lock held below the fault (a null read inside the locked A* left the map's stripe held, the + // next tick threw on the relock, and the world thread hung until the freeze detector fired). The guard records the lock so the + // catch can release it (ReleaseNavLockAfterFault); a normal exit clears the record first, so the lock is never unlocked twice. + thread_local std::mutex* t_navLockHeld = nullptr; + + class NavExecGuard + { + public: + explicit NavExecGuard(std::mutex& m) : _m(m) { _m.lock(); t_navLockHeld = &_m; } + ~NavExecGuard() { t_navLockHeld = nullptr; _m.unlock(); } + NavExecGuard(NavExecGuard const&) = delete; + NavExecGuard& operator=(NavExecGuard const&) = delete; + private: + std::mutex& _m; + }; +} + +void ReleaseNavLockAfterFault() +{ + if (std::mutex* held = t_navLockHeld) + { + t_navLockHeld = nullptr; + held->unlock(); + } } ////////////////// PathGenerator ////////////////// @@ -144,7 +170,7 @@ bool PathGenerator::CalculatePathImpl(float srcX, float srcY, float srcZ, float // SHARED non-thread-safe dtNavMeshQuery — serialize the node-pool-mutating A* // per map (see NavExecLock above). Guards findPath + moveAlongSurface against // the cross-thread node-pool corruption that crashed the server 2026-06-27. - std::lock_guard navGuard(NavExecLock(_source->GetMapId())); + NavExecGuard navGuard(NavExecLock(_source->GetMapId())); BuildPolyPath(start, dest); } diff --git a/src/server/game/Movement/PathGenerator.h b/src/server/game/Movement/PathGenerator.h index 0b1b720354..877af02eb4 100644 --- a/src/server/game/Movement/PathGenerator.h +++ b/src/server/game/Movement/PathGenerator.h @@ -27,6 +27,9 @@ class WorldObject; +// Unlocks the nav lock the calling thread still holds after a caught hardware fault skipped its destructor (MapUpdater). No-op otherwise. +TC_GAME_API void ReleaseNavLockAfterFault(); + // 74*4.0f=296y number_of_points*interval = max_path_len // this is way more than actual evade range // I think we can safely cut those down even more