Jelajahi Sumber

Backends: SDL3: following SDL3 reverting their change, result of SDL_GetGamepads must be freed. (#7918, #7898, #7807)

Matt Guerrette 1 tahun lalu
induk
melakukan
6a7319543c
2 mengubah file dengan 6 tambahan dan 2 penghapusan
  1. 3 1
      backends/imgui_impl_sdl3.cpp
  2. 3 1
      docs/CHANGELOG.txt

+ 3 - 1
backends/imgui_impl_sdl3.cpp

@@ -21,6 +21,7 @@
 
 
 // CHANGELOG
 // CHANGELOG
 // (minor and older changes stripped away, please see git history for details)
 // (minor and older changes stripped away, please see git history for details)
+//  2024-09-03: Update for SDL3 api changes: SDL_GetGamepads() memory ownership revert. (#7918, #7898, #7807)
 //  2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
 //  2024-08-22: moved some OS/backend related function pointers from ImGuiIO to ImGuiPlatformIO:
 //               - io.GetClipboardTextFn    -> platform_io.Platform_GetClipboardTextFn
 //               - io.GetClipboardTextFn    -> platform_io.Platform_GetClipboardTextFn
 //               - io.SetClipboardTextFn    -> platform_io.Platform_SetClipboardTextFn
 //               - io.SetClipboardTextFn    -> platform_io.Platform_SetClipboardTextFn
@@ -672,7 +673,7 @@ static void ImGui_ImplSDL3_UpdateGamepads()
     {
     {
         ImGui_ImplSDL3_CloseGamepads();
         ImGui_ImplSDL3_CloseGamepads();
         int sdl_gamepads_count = 0;
         int sdl_gamepads_count = 0;
-        const SDL_JoystickID* sdl_gamepads = SDL_GetGamepads(&sdl_gamepads_count);
+        SDL_JoystickID* sdl_gamepads = SDL_GetGamepads(&sdl_gamepads_count);
         for (int n = 0; n < sdl_gamepads_count; n++)
         for (int n = 0; n < sdl_gamepads_count; n++)
             if (SDL_Gamepad* gamepad = SDL_OpenGamepad(sdl_gamepads[n]))
             if (SDL_Gamepad* gamepad = SDL_OpenGamepad(sdl_gamepads[n]))
             {
             {
@@ -681,6 +682,7 @@ static void ImGui_ImplSDL3_UpdateGamepads()
                     break;
                     break;
             }
             }
         bd->WantUpdateGamepadsList = false;
         bd->WantUpdateGamepadsList = false;
+        SDL_free(sdl_gamepads);
     }
     }
 
 
     // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
     // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.

+ 3 - 1
docs/CHANGELOG.txt

@@ -96,6 +96,8 @@ Other changes:
   provide a way to do a portable sleep. (#7844)
   provide a way to do a portable sleep. (#7844)
 - Backends: SDL2, SDL3: ignore events of other SDL windows. (#7853) [@madebr, @ocornut]
 - Backends: SDL2, SDL3: ignore events of other SDL windows. (#7853) [@madebr, @ocornut]
 - Backends: SDL2, SDL3: storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
 - Backends: SDL2, SDL3: storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
+- Backends: SDL3: Update for API changes: SDL_GetGamepads() memory ownership logic was reverted back
+  by SDL3 on July 27. (#7918, #7898, #7807) [@cheyao, @MattGuerrette]
 - Backends: GLFW: passing null window to glfwGetClipboardString()/glfwSetClipboardString()
 - Backends: GLFW: passing null window to glfwGetClipboardString()/glfwSetClipboardString()
   since GLFW own tests are doing that and it seems unnecessary.
   since GLFW own tests are doing that and it seems unnecessary.
 - Backends: SDL2, SDL3, GLFW, OSX, Allegro: update to set function handlers in ImGuiPlatformIO
 - Backends: SDL2, SDL3, GLFW, OSX, Allegro: update to set function handlers in ImGuiPlatformIO
@@ -103,7 +105,7 @@ Other changes:
 - Examples: GLFW (all), SDL2 (all), SDL3 (all), Win32+OpenGL3: rework examples main loop
 - Examples: GLFW (all), SDL2 (all), SDL3 (all), Win32+OpenGL3: rework examples main loop
   to handle minimization without burning CPU or GPU by running unthrottled code. (#7844)
   to handle minimization without burning CPU or GPU by running unthrottled code. (#7844)
 
 
-
+Backends: SDL3: following SDL3 reverting their change, result of SDL_GetGamepads must be freed. (#7918, #7898)
 
 
 -----------------------------------------------------------------------
 -----------------------------------------------------------------------
  VERSION 1.91.0 (Released 2024-07-30)
  VERSION 1.91.0 (Released 2024-07-30)