Use Future::CancelOrWait in pathfinder Deinit

If the pathfinding tasks are running, they might reference now-deleted
variables. CancelOrWait prevents this.
Remove `Future::Cancel()` altogether as that was its only use and the
functions seems dangerous.

Introduced with 0ebc08b13c

Patch by: phosit
Reviewed By: wraitii
Differential Revision: https://code.wildfiregames.com/D4831
This was SVN commit r27310.
This commit is contained in:
wraitii
2022-12-28 11:34:04 +00:00
parent 92153b0afb
commit a333c8f355
3 changed files with 3 additions and 15 deletions
-11
View File
@@ -222,17 +222,6 @@ public:
m_SharedState.reset();
}
/**
* Cancels the task (without waiting).
* The result is always invalid, even if the task had completed before.
* Note that this cannot stop started tasks.
*/
void Cancel()
{
if (m_SharedState)
m_SharedState->Cancel();
m_SharedState.reset();
}
protected:
std::shared_ptr<SharedState> m_SharedState;
};
+1 -2
View File
@@ -95,8 +95,7 @@ public:
{
Future<NonDef> future;
std::function<void()> task = future.Wrap([]() { return 1; });
future.Cancel();
future.Wait();
future.CancelOrWait();
TS_ASSERT_THROWS(future.Get(), const Future<NonDef>::BadFutureAccess&);
}
*/
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -107,7 +107,7 @@ void CCmpPathfinder::Deinit()
// Wait on all pathfinding tasks.
for (Future<void>& future : m_Futures)
future.Cancel();
future.CancelOrWait();
m_Futures.clear();
SAFE_DELETE(m_AtlasOverlay);