Fix async tasks destruction to wait on the dependencies in chain

This commit is contained in:
Wojtek Figat
2025-11-13 22:53:52 +01:00
parent 69173803bf
commit 3888c4ba21
2 changed files with 28 additions and 2 deletions

View File

@@ -226,6 +226,27 @@ void Task::OnEnd()
{
ASSERT(!IsRunning());
// Add to delete
DeleteObject(30.0f, false);
if (_continueWith && !_continueWith->IsEnded())
{
// Let next task do the cleanup (to ensure whole tasks chain shares the lifetime)
_continueWith->_rootForRemoval = _rootForRemoval ? _rootForRemoval : this;
}
else
{
constexpr float timeToLive = 30.0f;
// Remove task chain starting from the root
if (_rootForRemoval)
{
auto task = _rootForRemoval;
while (task != this)
{
task->DeleteObject(timeToLive, false);
task = task->_continueWith;
}
}
// Add to delete
DeleteObject(timeToLive, false);
}
}

View File

@@ -63,6 +63,11 @@ protected:
/// </summary>
Task* _continueWith = nullptr;
/// <summary>
/// The task that's starts removal chain, used to sync whole task chain lifetime.
/// </summary>
Task* _rootForRemoval = nullptr;
void SetState(TaskState state)
{
Platform::AtomicStore((int64 volatile*)&_state, (uint64)state);