From 47a07d8476b4f1b0438902ff322433eab0256051 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 4 Apr 2023 21:43:48 +0200 Subject: [PATCH 1/3] ButtonBehavior: Fixed an edge case where changing widget type/behavior while active and using same id could lead to an assert. (#6304) + Demo: use BeginDisabled() block in BackendFlags section. I'd still consider this undefined behavior as some combination may not work properly, but let's fix things while we can as we encounter them. --- docs/CHANGELOG.txt | 2 ++ imgui.h | 2 +- imgui_demo.cpp | 14 +++++++------- imgui_widgets.cpp | 7 ++++++- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a96410b0..123985a6 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -56,6 +56,8 @@ Other changes: horizontal mouse-wheel (or Shift + WheelY). (#2702) - Rendering: Using adaptative tesselation for: RadioButton, ColorEdit preview circles, Windows Close and Collapse Buttons. +- ButtonBehavior: Fixed an edge case where changing widget type/behavior while active + and using same id could lead to an assert. (#6304) - Misc: Fixed ImVec2 operator[] violating aliasing rules causing issue with Intel C++ compiler. (#6272) [@BayesBug] - IO: Input queue trickling adjustment for touch screens. (#2702, #4921) diff --git a/imgui.h b/imgui.h index c974d9c7..02ef16f3 100644 --- a/imgui.h +++ b/imgui.h @@ -23,7 +23,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') #define IMGUI_VERSION "1.89.5 WIP" -#define IMGUI_VERSION_NUM 18948 +#define IMGUI_VERSION_NUM 18949 #define IMGUI_HAS_TABLE /* diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 051f6f5b..5849ffbe 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -483,13 +483,13 @@ void ImGui::ShowDemoWindow(bool* p_open) "Those flags are set by the backends (imgui_impl_xxx files) to specify their capabilities.\n" "Here we expose them as read-only fields to avoid breaking interactions with your backend."); - // Make a local copy to avoid modifying actual backend flags. - // FIXME: We don't use BeginDisabled() to keep label bright, maybe we need a BeginReadonly() equivalent.. - ImGuiBackendFlags backend_flags = io.BackendFlags; - ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", &backend_flags, ImGuiBackendFlags_HasGamepad); - ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &backend_flags, ImGuiBackendFlags_HasMouseCursors); - ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", &backend_flags, ImGuiBackendFlags_HasSetMousePos); - ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", &backend_flags, ImGuiBackendFlags_RendererHasVtxOffset); + // FIXME: Maybe we need a BeginReadonly() equivalent to keep label bright? + ImGui::BeginDisabled(); + ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", &io.BackendFlags, ImGuiBackendFlags_HasGamepad); + ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &io.BackendFlags, ImGuiBackendFlags_HasMouseCursors); + ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", &io.BackendFlags, ImGuiBackendFlags_HasSetMousePos); + ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", &io.BackendFlags, ImGuiBackendFlags_RendererHasVtxOffset); + ImGui::EndDisabled(); ImGui::TreePop(); ImGui::Spacing(); } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index a80fe0a6..8ea6e443 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -638,7 +638,12 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool g.ActiveIdClickOffset = g.IO.MousePos - bb.Min; const int mouse_button = g.ActiveIdMouseButton; - if (IsMouseDown(mouse_button, test_owner_id)) + if (mouse_button == -1) + { + // Fallback for the rare situation were g.ActiveId was set programmatically or from another widget (e.g. #6304). + ClearActiveID(); + } + else if (IsMouseDown(mouse_button, test_owner_id)) { held = true; } From 8738ed88f081183436261cde35a6cdd2fefd5c0b Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 6 Apr 2023 17:16:05 +0200 Subject: [PATCH 2/3] Fixed FindWindowSettingsByID() being able to return a deleted setting. --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 4e3b6050..02c5dd8e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12840,7 +12840,7 @@ ImGuiWindowSettings* ImGui::FindWindowSettingsByID(ImGuiID id) { ImGuiContext& g = *GImGui; for (ImGuiWindowSettings* settings = g.SettingsWindows.begin(); settings != NULL; settings = g.SettingsWindows.next_chunk(settings)) - if (settings->ID == id) + if (settings->ID == id && !settings->WantDelete) return settings; return NULL; } From a7703fe6f74a78db58040813f9baae66b4fd053d Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 6 Apr 2023 19:12:10 +0200 Subject: [PATCH 3/3] Backends: SDL2/SDL3: Avoid callng SDL_StartTextInput()/SDL_StopTextInput(). (#6306, #6071, #1953) Amend 734c6af187f80472100a940f59bf505ef588acb8 --- backends/imgui_impl_sdl2.cpp | 6 +----- backends/imgui_impl_sdl3.cpp | 6 +----- docs/CHANGELOG.txt | 3 +++ 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index c64d9652..1f8425a9 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -18,6 +18,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-06: Inputs: Avoid callng SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306) // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702) // 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644) // 2023-02-07: Implement IME handler (io.SetPlatformImeDataFn will call SDL_SetTextInputRect()/SDL_StartTextInput()). @@ -146,11 +147,6 @@ static void ImGui_ImplSDL2_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeDa r.w = 1; r.h = (int)data->InputLineHeight; SDL_SetTextInputRect(&r); - SDL_StartTextInput(); - } - else - { - SDL_StopTextInput(); } } diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index c555afb5..57736066 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -19,6 +19,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-04-06: Inputs: Avoid callng SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306) // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702) // 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644) // 2023-02-07: Forked "imgui_impl_sdl2" into "imgui_impl_sdl3". Removed version checks for old feature. Refer to imgui_impl_sdl2.cpp for older changelog. @@ -96,11 +97,6 @@ static void ImGui_ImplSDL3_SetPlatformImeData(ImGuiViewport*, ImGuiPlatformImeDa r.w = 1; r.h = (int)data->InputLineHeight; SDL_SetTextInputRect(&r); - SDL_StartTextInput(); - } - else - { - SDL_StopTextInput(); } } diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 123985a6..f6e18e6c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -80,6 +80,9 @@ Other changes: - Backends: Win32: Added support for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen/Pen. (#2334, #2702) - Backends: SDL2/SDL3: Added support for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen. This is relying on SDL passing SDL_TOUCH_MOUSEID in the event's 'which' field. (#2334, #2702) +- Backends: SDL2/SDL3: Avoid callng SDL_StartTextInput()/SDL_StopTextInput() as they actually + block text input input and don't only pertain to IME. It's unclear exactly what their relation + is to other IME function such as SDL_SetTextInputRect(). (#6306, #6071, #1953) - Backends: GLFW: Added support on Win32 only for io.AddMouseSourceEvent() to discriminate Mouse/TouchScreen/Pen. (#2334, #2702) - Backends: GLFW: Fixed key modifiers handling on secondary viewports. (#6248, #6034) [@aiekick]