From b32395ade9455756b20d55d6c69641b35ebb2812 Mon Sep 17 00:00:00 2001 From: mosquito chang Date: Sun, 18 Aug 2024 14:46:34 +0200 Subject: [PATCH] Fix `InputMap::event_get_index` to handle unmatched events correctly --- core/input/input_map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index ddeee9d765a..5cd02cf39d8 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -253,8 +253,8 @@ bool InputMap::event_is_action(const Ref &p_event, const StringName int InputMap::event_get_index(const Ref &p_event, const StringName &p_action, bool p_exact_match) const { int index = -1; - event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index); - return index; + bool valid = event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index); + return valid ? index : -1; } bool InputMap::event_get_action_status(const Ref &p_event, const StringName &p_action, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {