فهرست منبع

SDL_GetWindows() follows the SDL_GetStringRule

Sam Lantinga 9 ماه پیش
والد
کامیت
bdafc8e212
4فایلهای تغییر یافته به همراه8 افزوده شده و 9 حذف شده
  1. 4 4
      include/SDL3/SDL_video.h
  2. 1 1
      src/dynapi/SDL_dynapi_procs.h
  3. 2 2
      src/video/SDL_video.c
  4. 1 2
      test/testautomation_video.c

+ 4 - 4
include/SDL3/SDL_video.h

@@ -791,15 +791,15 @@ extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetWindowPixelFormat(SDL_Window
 /**
  * Get a list of valid windows.
  *
+ * The returned array follows the SDL_GetStringRule, and will be automatically freed later.
+ *
  * \param count a pointer filled in with the number of windows returned, may
  *              be NULL.
- * \returns a 0 terminated array of window pointers which should be freed with
- *          SDL_free(), or NULL on error; call SDL_GetError() for more
- *          details.
+ * \returns a NULL terminated array of SDL_Window pointers or NULL on failure; call SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
  */
-extern SDL_DECLSPEC SDL_Window **SDLCALL SDL_GetWindows(int *count);
+extern SDL_DECLSPEC SDL_Window * const *SDLCALL SDL_GetWindows(int *count);
 
 /**
  * Create a window with the specified dimensions and flags.

+ 1 - 1
src/dynapi/SDL_dynapi_procs.h

@@ -533,7 +533,7 @@ SDL_DYNAPI_PROC(int,SDL_GetWindowSizeInPixels,(SDL_Window *a, int *b, int *c),(a
 SDL_DYNAPI_PROC(SDL_Surface*,SDL_GetWindowSurface,(SDL_Window *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_GetWindowSurfaceVSync,(SDL_Window *a, int *b),(a,b),return)
 SDL_DYNAPI_PROC(const char*,SDL_GetWindowTitle,(SDL_Window *a),(a),return)
-SDL_DYNAPI_PROC(SDL_Window**,SDL_GetWindows,(int *a),(a),return)
+SDL_DYNAPI_PROC(SDL_Window* const*,SDL_GetWindows,(int *a),(a),return)
 SDL_DYNAPI_PROC(const char * const *,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return)
 SDL_DYNAPI_PROC(const char * const *,SDL_GlobStorageDirectory,(SDL_Storage *a, const char *b, const char *c, SDL_GlobFlags d, int *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(SDL_bool,SDL_HapticEffectSupported,(SDL_Haptic *a, const SDL_HapticEffect *b),(a,b),return)

+ 2 - 2
src/video/SDL_video.c

@@ -2056,7 +2056,7 @@ void SDL_ToggleDragAndDropSupport(void)
     }
 }
 
-SDL_Window **SDLCALL SDL_GetWindows(int *count)
+SDL_Window * const *SDLCALL SDL_GetWindows(int *count)
 {
     if (count) {
         *count = 0;
@@ -2091,7 +2091,7 @@ SDL_Window **SDLCALL SDL_GetWindows(int *count)
     if (count) {
         *count = num_added;
     }
-    return windows;
+    return SDL_FreeLater(windows);
 }
 
 static void ApplyWindowFlags(SDL_Window *window, SDL_WindowFlags flags)

+ 1 - 2
test/testautomation_video.c

@@ -13,7 +13,7 @@
 static SDL_Window *createVideoSuiteTestWindow(const char *title)
 {
     SDL_Window *window;
-    SDL_Window **windows;
+    SDL_Window * const *windows;
     SDL_Event event;
     int w, h;
     int count;
@@ -34,7 +34,6 @@ static SDL_Window *createVideoSuiteTestWindow(const char *title)
     windows = SDL_GetWindows(&count);
     SDLTest_AssertCheck(windows != NULL, "Validate that returned window list is not NULL");
     SDLTest_AssertCheck(windows[0] == window, "Validate that the window is first in the window list");
-    SDL_free(windows);
 
     /* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen.
      * This is required for the mouse/keyboard grab tests to pass.