Pathfinding: no null read for a polygon without detail edges, and a caught fault releases the nav lock (#76)
- dtNavMesh closest-point-on-detail-mesh: a polygon whose detail mesh has no qualifying edge (no triangles, or none with a boundary flag in the boundary-only pass) left pmin/pmax null and dtVlerp read through them. The position the caller already put into `closest` is kept instead. - PathGenerator holds a per-map mutex around the A*. MapUpdater catches a hardware fault in Map::Update and skips the tick, but that unwind does not run the destructor of the lock, so the map's lock stayed held for good, the next tick threw on the relock and the world thread hung. The lock guard now records the lock the thread holds, and MapUpdater releases it in the catch through ReleaseNavLockAfterFault(). A normal exit clears the record first, so the lock is never unlocked twice.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "Log.h"
|
||||
#include "Map.h"
|
||||
#include "Metric.h"
|
||||
#include "PathGenerator.h"
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,32 @@ namespace
|
||||
static std::array<std::mutex, kNavExecLockStripes> 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<std::mutex> navGuard(NavExecLock(_source->GetMapId()));
|
||||
NavExecGuard navGuard(NavExecLock(_source->GetMapId()));
|
||||
BuildPolyPath(start, dest);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user