From 2338e03554d8d30938f274d2beb8f294547ee953 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 17 Feb 2023 10:31:49 +0100 Subject: [PATCH] Fix crash when unbinding from `Delegate` from other thread during invocation Caused by `callee` being invalid thus it's better to read function pointer again to ensure that both are valid before calling function. --- Source/Engine/Core/Delegate.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Core/Delegate.h b/Source/Engine/Core/Delegate.h index ffb78dfeb..21a4374ea 100644 --- a/Source/Engine/Core/Delegate.h +++ b/Source/Engine/Core/Delegate.h @@ -617,12 +617,11 @@ public: FunctionType* bindings = (FunctionType*)Platform::AtomicRead((intptr volatile*)&_ptr); for (intptr i = 0; i < size; i++) { - auto function = (StubSignature)Platform::AtomicRead((intptr volatile*)&bindings[i]._function); - if (function != nullptr) - { - auto callee = (void*)Platform::AtomicRead((intptr volatile*)&bindings[i]._callee); + auto function = (StubSignature)Platform::AtomicRead((intptr volatile*)&bindings->_function); + auto callee = (void*)Platform::AtomicRead((intptr volatile*)&bindings->_callee); + if (function != nullptr && function == (StubSignature)Platform::AtomicRead((intptr volatile*)&bindings->_function)) function(callee, Forward(params)...); - } + ++bindings; } } };