Skip to content

Commit

Permalink
fix: copy args before invoking callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Sep 13, 2023
1 parent 12d618f commit 923d196
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/lua/callbacks/events_callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ class EventsCallbacks {
template <typename CallbackFunc, typename... Args>
void executeCallback(EventCallback_t eventType, CallbackFunc callbackFunc, Args &&... args) {
for (const auto &callback : getCallbacksByType(eventType)) {
auto argsCopy = std::make_tuple(args...);
if (callback && callback->isLoadedCallback()) {
((*callback).*callbackFunc)(std::forward<Args>(args)...);
std::apply(
[&callback, &callbackFunc](auto &&... args) {
((*callback).*callbackFunc)(std::forward<decltype(args)>(args)...);
},
argsCopy
);
}
}
}
Expand All @@ -96,8 +102,14 @@ class EventsCallbacks {
bool allCallbacksSucceeded = true;

for (const auto &callback : getCallbacksByType(eventType)) {
if (callback && callback->isLoadedCallback()) { // Verifique se o callback é não nulo
bool callbackResult = ((*callback).*callbackFunc)(std::forward<Args>(args)...);
auto argsCopy = std::make_tuple(args...);
if (callback && callback->isLoadedCallback()) {
bool callbackResult = std::apply(
[&callback, &callbackFunc](auto &&... args) {
return ((*callback).*callbackFunc)(std::forward<decltype(args)>(args)...);
},
argsCopy
);
allCallbacksSucceeded = allCallbacksSucceeded && callbackResult;
}
}
Expand Down

0 comments on commit 923d196

Please sign in to comment.