Skip to content

Commit

Permalink
Fix CallScope operator() causing infinite loop when called by hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Panakotta00 committed Mar 12, 2020
1 parent 18dda8e commit d287e7f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Source/SML/mod/hooking.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ struct CallScope<void(*)(Args...)> {
}

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...);
}
Expand Down Expand Up @@ -102,9 +104,11 @@ struct CallScope<Result(*)(Args...)> {
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...);
}
Expand Down

0 comments on commit d287e7f

Please sign in to comment.