From 175fd31431d2b9edab7c491c4727eeab0c4cdcfe Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 5 Jun 2024 18:00:00 +0200 Subject: [PATCH] Fix `Delegate` invoke to copy arguments values to each call instead of passing as reference --- Source/Engine/Content/AssetReference.h | 2 +- Source/Engine/Core/Delegate.h | 8 ++++---- Source/Engine/Core/Templates.h | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Content/AssetReference.h b/Source/Engine/Content/AssetReference.h index dfa52c742..3395080cc 100644 --- a/Source/Engine/Content/AssetReference.h +++ b/Source/Engine/Content/AssetReference.h @@ -105,7 +105,7 @@ public: OnSet(other._asset); } - AssetReference(AssetReference&& other) + AssetReference(AssetReference&& other) noexcept { OnSet(other._asset); other.OnSet(nullptr); diff --git a/Source/Engine/Core/Delegate.h b/Source/Engine/Core/Delegate.h index c33b20fa4..501240321 100644 --- a/Source/Engine/Core/Delegate.h +++ b/Source/Engine/Core/Delegate.h @@ -138,7 +138,7 @@ public: /// /// Binds a static function. /// - template + template void Bind() { if (_lambda) @@ -288,6 +288,7 @@ protected: // Single allocation for list of binded functions. Thread-safe access via atomic operations. Removing binded function simply clears the entry to handle function unregister during invocation. intptr volatile _ptr = 0; intptr volatile _size = 0; + typedef void (*StubSignature)(void*, Params...); #else struct Data { @@ -297,7 +298,6 @@ protected: // Holds pointer to Data with Functions and Locker. Thread-safe access via atomic operations. intptr volatile _data = 0; #endif - typedef void (*StubSignature)(void*, Params...); public: Delegate() @@ -811,7 +811,7 @@ public: 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)...); + function(callee, params...); ++bindings; } #else @@ -823,7 +823,7 @@ public: { const FunctionType& item = i->Item; ASSERT_LOW_LAYER(item._function); - item._function(item._callee, Forward(params)...); + item._function(item._callee, params...); } #endif } diff --git a/Source/Engine/Core/Templates.h b/Source/Engine/Core/Templates.h index ace9bf98c..462fa5024 100644 --- a/Source/Engine/Core/Templates.h +++ b/Source/Engine/Core/Templates.h @@ -319,7 +319,6 @@ inline T&& Forward(typename TRemoveReference::Type& t) noexcept template inline T&& Forward(typename TRemoveReference::Type&& t) noexcept { - static_assert(!TIsLValueReference::Value, "Can not forward an rvalue as an lvalue."); return static_cast(t); }