From e39c2552ac8521328caa77df20cf39a1bf14e0d4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 14 Mar 2023 15:56:38 +0100 Subject: [PATCH] Backends: GLFW: Avoid using glfwGetError() and glfwGetGamepadState() on Emscripten. (#6240) --- backends/imgui_impl_glfw.cpp | 8 +++++--- docs/CHANGELOG.txt | 4 +++- examples/example_apple_opengl2/main.mm | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index f0e70a6dc..29d502b0f 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -16,6 +16,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-03-14: Emscripten: Avoid using glfwGetError() and glfwGetGamepadState() which are not correctly implemented in Emscripten emulation. (#6240) // 2023-02-03: Emscripten: Registering custom low-level mouse wheel handler to get more accurate scrolling impulses on Emscripten. (#4019, #6096) // 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty. // 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908) @@ -95,6 +96,7 @@ #endif #define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetGamepadState() new api #define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName() +#define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError() // GLFW data enum GlfwClientApi @@ -323,7 +325,7 @@ static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode) GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr); const char* key_name = glfwGetKeyName(key, scancode); glfwSetErrorCallback(prev_error_callback); -#if (GLFW_VERSION_COMBINED >= 3300) // Eat errors (see #5908) +#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908) (void)glfwGetError(NULL); #endif if (key_name && key_name[0] != 0 && key_name[1] == 0) @@ -536,7 +538,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); #endif glfwSetErrorCallback(prev_error_callback); -#if (GLFW_VERSION_COMBINED >= 3300) // Eat errors (see #5785) +#if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908) (void)glfwGetError(NULL); #endif @@ -669,7 +671,7 @@ static void ImGui_ImplGlfw_UpdateGamepads() return; io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; -#if GLFW_HAS_GAMEPAD_API +#if GLFW_HAS_GAMEPAD_API && !defined(__EMSCRIPTEN__) GLFWgamepadstate gamepad; if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad)) return; diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a974e47e2..24e369d58 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -87,8 +87,10 @@ Other changes: program was pending deletion, attempting to restore it would error. (#6220, #6224) [@Cyphall] - Backends: Win32: Use WM_NCMOUSEMOVE / WM_NCMOUSELEAVE to track mouse positions over non-client area (e.g. OS decorations) when app is not focused. (#6045, #6162) -- Backends: SDL2, SDL3: Accept SDL_GetPerformanceCounter() not returning a monotonically +- Backends: SDL2, SDL3: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644) [@adamkewley] +- Backends: GLFW: Avoid using glfwGetError() and glfwGetGamepadState() on Emscripten, which + recently updated its GLFW emulation layer to GLFW 3.3 without supporting those. (#6240) - Examples: Android: Fixed example build for Gradle 8. (#6229, #6227) [@duddel] - Examples: Updated all examples application to enable ImGuiConfigFlags_NavEnableKeyboard and ImGuiConfigFlags_NavEnableGamepad by default. (#787) diff --git a/examples/example_apple_opengl2/main.mm b/examples/example_apple_opengl2/main.mm index 11b5bf409..38739ff63 100644 --- a/examples/example_apple_opengl2/main.mm +++ b/examples/example_apple_opengl2/main.mm @@ -72,6 +72,7 @@ -(void)updateAndDrawDemoView { // Start the Dear ImGui frame + ImGuiIO& io = ImGui::GetIO(); ImGui_ImplOpenGL2_NewFrame(); ImGui_ImplOSX_NewFrame(self); ImGui::NewFrame();