From d3c49be80fd7e0f6fb8b7394413f1ce5c500257b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 17 Apr 2025 10:40:05 +0200 Subject: [PATCH] Fix crash when GPUTask gets deleted before sync happens --- Source/Engine/Graphics/Async/GPUTask.h | 2 ++ Source/Engine/Graphics/Async/GPUTasksManager.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/Source/Engine/Graphics/Async/GPUTask.h b/Source/Engine/Graphics/Async/GPUTask.h index 7bbff5df8..f3e4cf269 100644 --- a/Source/Engine/Graphics/Async/GPUTask.h +++ b/Source/Engine/Graphics/Async/GPUTask.h @@ -58,6 +58,8 @@ protected: { } + ~GPUTask(); + public: /// /// Gets a task type. diff --git a/Source/Engine/Graphics/Async/GPUTasksManager.cpp b/Source/Engine/Graphics/Async/GPUTasksManager.cpp index 87311779b..6db7ee199 100644 --- a/Source/Engine/Graphics/Async/GPUTasksManager.cpp +++ b/Source/Engine/Graphics/Async/GPUTasksManager.cpp @@ -7,6 +7,16 @@ #include "Engine/Core/Types/String.h" #include "Engine/Graphics/GPUDevice.h" +GPUTask::~GPUTask() +{ + // Ensure to dereference task + if (auto context = _context) + { + _context = nullptr; + context->OnCancelSync(this); + } +} + void GPUTask::Execute(GPUTasksContext* context) { ASSERT(IsQueued() && _context == nullptr);