1
0
forked from mirrors/0ad

Don't execute the task when no Future awaits it anymore

Summary:
Most of the times the callback stores a reference to a variable in scope
where the `Future` is in. When the scope is left the reference get's
dangling. `CancelOrWait` is called in multiple places (mostly
destructors) to ensure the callback isn't executed anymore.
This patch deduplicates thous calls to `CancelOrWait`.

Refs: #5874

Comments by: @Stan, @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5208
This was SVN commit r28128.
This commit is contained in:
phosit
2024-06-25 19:03:01 +00:00
parent 5a43f514dc
commit f5b416c63b
5 changed files with 29 additions and 51 deletions
+1 -6
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2023 Wildfire Games.
/* Copyright (C) 2024 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -1331,11 +1331,6 @@ struct CMapReader::GeneratorState
{
std::atomic<int> progress{1};
Future<Script::StructuredClone> task;
~GeneratorState()
{
task.CancelOrWait();
}
};
int CMapReader::StartMapGeneration(const CStrW& scriptFile)