--- a/rts/Sim/Path/QTPFS/Systems/SyncUpdatedPathsSystem.h +++ b/rts/Sim/Path/QTPFS/Systems/SyncUpdatedPathsSystem.h @@ -9,6 +9,7 @@ public: static void Init(); static void Update(); + static void WaitForPending(); static void Shutdown(); }; --- a/rts/Sim/Path/QTPFS/Systems/SyncUpdatedPathsSystem.cpp +++ b/rts/Sim/Path/QTPFS/Systems/SyncUpdatedPathsSystem.cpp @@ -36,14 +36,8 @@ SCOPED_TIMER("ECS::SyncUpdatedPathsSystem::Update"); auto* pm = dynamic_cast(pathManager); - auto& comp = systemGlobals.GetSystemComponent(); + WaitForPending(); - // Ensure any outstanding pathing tasks are completed before synchronisation. - if (comp.backgroundTask){ - wait_for_mt_background(comp.backgroundTask); - comp.backgroundTask.reset(); - } - auto pathSearchView = registry.group(); for (auto pathSearchEntity : pathSearchView) { @@ -64,7 +58,12 @@ RECOIL_DETAILED_TRACY_ZONE; systemUtils.OnUpdate().disconnect<&SyncUpdatedPathsSystem::Update>(); - // drain the task group if it still exists, to ensure all tasks have completed before we shutdown. + WaitForPending(); +} + +void SyncUpdatedPathsSystem::WaitForPending() { + // Finish the search work without publishing its results. Update applies those + // results at the existing point in the next simulation frame. auto& comp = systemGlobals.GetSystemComponent(); if (comp.backgroundTask){ wait_for_mt_background(comp.backgroundTask); --- a/rts/Game/Game.cpp +++ b/rts/Game/Game.cpp @@ -92,6 +92,7 @@ #include "Sim/MoveTypes/MoveDefHandler.h" #include "Sim/MoveTypes/MoveTypeFactory.h" #include "Sim/Path/IPathManager.h" +#include "Sim/Path/QTPFS/Systems/SyncUpdatedPathsSystem.h" #include "Sim/Projectiles/ExplosionGenerator.h" #include "Sim/Projectiles/Projectile.h" #include "Sim/Projectiles/ProjectileHandler.h" @@ -1856,6 +1857,12 @@ teamHandler.GameFrame(gs->frameNum); playerHandler.GameFrame(gs->frameNum); eventHandler.GameFramePost(gs->frameNum); + + // Background searches may overlap the remainder of this frame, but must + // finish before the next frame mutates units and path request storage. + // Presentation/catch-up timing must not decide the resulting waypoints. + if (pathManager->GetPathFinderType() == QTPFS_TYPE) + QTPFS::SyncUpdatedPathsSystem::WaitForPending(); } lastSimFrameTime = spring_gettime();