mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user