Skip to content

Commit

Permalink
Backends: GLFW: Avoid using glfwGetError() and glfwGetGamepadState() …
Browse files Browse the repository at this point in the history
…on Emscripten. (#6240)
  • Loading branch information
ocornut committed Mar 14, 2023
1 parent cc2177d commit 97a737d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions backends/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 97a737d

Please sign in to comment.