Skip to content

Commit b8d4e1b

Browse files
committed
fix: fix some events cancelled wrongly
1 parent d97c227 commit b8d4e1b

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/legacy/api/EventAPI.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,15 @@ inline std::string EventTypeToString(EVENT_TYPES e) { return std::string(magic_e
166166

167167
// 调用事件监听函数,拦截返回RETURN_VALUE
168168
#define CallEventRtnValue(TYPE, RETURN_VALUE, ...) \
169-
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
170-
bool isCancelled; \
169+
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
170+
bool isCancelled = false; \
171171
for (auto& listener : nowList) { \
172172
EngineScope enter(listener.engine); \
173173
try { \
174174
auto result = listener.func.get().call({}, __VA_ARGS__); \
175-
if (result.isBoolean() && result.asBoolean().value() == false) isCancelled = true; \
175+
if (result.isBoolean() && result.asBoolean().value() == false) { \
176+
isCancelled = true; \
177+
} \
176178
} \
177179
LISTENER_CATCH(TYPE) \
178180
} \
@@ -182,13 +184,15 @@ inline std::string EventTypeToString(EVENT_TYPES e) { return std::string(magic_e
182184

183185
// 调用事件监听函数,拦截返回
184186
#define CallEventVoid(TYPE, ...) \
185-
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
186-
bool isCancelled; \
187+
std::list<ListenerListType>& nowList = listenerList[int(TYPE)]; \
188+
bool isCancelled = false; \
187189
for (auto& listener : nowList) { \
188190
EngineScope enter(listener.engine); \
189191
try { \
190192
auto result = listener.func.get().call({}, __VA_ARGS__); \
191-
if (result.isBoolean() && result.asBoolean().value() == false) isCancelled = true; \
193+
if (result.isBoolean() && result.asBoolean().value() == false) { \
194+
isCancelled = true; \
195+
} \
192196
} \
193197
LISTENER_CATCH(TYPE) \
194198
} \

0 commit comments

Comments
 (0)