From 7dfbc4e57cd1de387cd4a849459ae2a7f6f2261d Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 15 Sep 2021 16:57:09 +0200 Subject: [PATCH] [HTML5] Fix wheel/touch callback modifying event after parse. The events should be duplicated or reinstantiated without assuming that parse_input will consume them immediately. --- platform/javascript/os_javascript.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 8262d17e39..c648efcac3 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -616,9 +616,10 @@ EM_BOOL OS_JavaScript::wheel_callback(int p_event_type, const EmscriptenWheelEve ev->set_button_mask(input->get_mouse_button_mask() | button_flag); input->parse_input_event(ev); - ev->set_pressed(false); - ev->set_button_mask(input->get_mouse_button_mask() & ~button_flag); - input->parse_input_event(ev); + Ref release = ev->duplicate(); + release->set_pressed(false); + release->set_button_mask(input->get_mouse_button_mask() & ~button_flag); + input->parse_input_event(release); return true; } @@ -632,7 +633,6 @@ bool OS_JavaScript::has_touchscreen_ui_hint() const { EM_BOOL OS_JavaScript::touch_press_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data) { OS_JavaScript *os = get_singleton(); Ref ev; - ev.instance(); int lowest_id_index = -1; for (int i = 0; i < p_event->numTouches; ++i) { const EmscriptenTouchPoint &touch = p_event->touches[i]; @@ -640,6 +640,7 @@ EM_BOOL OS_JavaScript::touch_press_callback(int p_event_type, const EmscriptenTo lowest_id_index = i; if (!touch.isChanged) continue; + ev.instance(); ev->set_index(touch.identifier); ev->set_position(compute_position_in_canvas(touch.clientX, touch.clientY)); os->touches[i] = ev->get_position(); @@ -659,7 +660,6 @@ EM_BOOL OS_JavaScript::touch_press_callback(int p_event_type, const EmscriptenTo EM_BOOL OS_JavaScript::touchmove_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data) { OS_JavaScript *os = get_singleton(); Ref ev; - ev.instance(); int lowest_id_index = -1; for (int i = 0; i < p_event->numTouches; ++i) { const EmscriptenTouchPoint &touch = p_event->touches[i]; @@ -667,6 +667,7 @@ EM_BOOL OS_JavaScript::touchmove_callback(int p_event_type, const EmscriptenTouc lowest_id_index = i; if (!touch.isChanged) continue; + ev.instance(); ev->set_index(touch.identifier); ev->set_position(compute_position_in_canvas(touch.clientX, touch.clientY)); Point2 &prev = os->touches[i];