From d287e7f09ba7b33a112ff7dce8ea322e349c5ae5 Mon Sep 17 00:00:00 2001 From: Panakotta00 Date: Thu, 12 Mar 2020 21:14:54 +0100 Subject: [PATCH] Fix CallScope operator() causing infinite loop when called by hook --- Source/SML/mod/hooking.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/SML/mod/hooking.h b/Source/SML/mod/hooking.h index 06fd9c185e..cf50078d49 100644 --- a/Source/SML/mod/hooking.h +++ b/Source/SML/mod/hooking.h @@ -52,15 +52,17 @@ struct CallScope { } void Cancel() { - this->forwardCall = false; + forwardCall = false; } inline void operator()(Args... args) { if (functionList == nullptr || handlerPtr >= functionList->size()) { function(args...); + forwardCall = false; } else { auto cachePtr = handlerPtr + 1; - functionList->at(handlerPtr++)(*this, args...); + auto& handler = functionList->at(handlerPtr++); + handler(*this, args...); if (handlerPtr == cachePtr && forwardCall) { (*this)(args...); } @@ -102,9 +104,11 @@ struct CallScope { inline void operator()(Args... args) { if (functionList == nullptr || handlerPtr >= functionList->size()) { result = function(args...); + this->forwardCall = false; } else { auto cachePtr = handlerPtr + 1; - functionList->at(handlerPtr++)(*this, args...); + auto handler = functionList->at(handlerPtr++); + handler(*this, args...); if (handlerPtr == cachePtr && forwardCall) { (*this)(args...); }