فهرست منبع

Fixed crash if mouse functions are used after video quit

Sam Lantinga 3 هفته پیش
والد
کامیت
aab95894a6
2فایلهای تغییر یافته به همراه9 افزوده شده و 10 حذف شده
  1. 6 0
      src/events/SDL_mouse.c
  2. 3 10
      src/video/cocoa/SDL_cocoamouse.m

+ 6 - 0
src/events/SDL_mouse.c

@@ -1168,6 +1168,12 @@ void SDL_QuitMouse(void)
     }
     SDL_free(SDL_mice);
     SDL_mice = NULL;
+
+    if (mouse->internal) {
+        SDL_free(mouse->internal);
+        mouse->internal = NULL;
+    }
+    SDL_zerop(mouse);
 }
 
 bool SDL_SetRelativeMouseTransform(SDL_MouseMotionTransformCallback transform, void *userdata)

+ 3 - 10
src/video/cocoa/SDL_cocoamouse.m

@@ -373,12 +373,12 @@ bool Cocoa_InitMouse(SDL_VideoDevice *_this)
 {
     NSPoint location;
     SDL_Mouse *mouse = SDL_GetMouse();
-    SDL_MouseData *internal = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData));
-    if (internal == NULL) {
+    SDL_MouseData *data = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData));
+    if (data == NULL) {
         return false;
     }
 
-    mouse->internal = internal;
+    mouse->internal = data;
     mouse->CreateCursor = Cocoa_CreateCursor;
     mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
     mouse->ShowCursor = Cocoa_ShowCursor;
@@ -585,13 +585,6 @@ void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y)
 
 void Cocoa_QuitMouse(SDL_VideoDevice *_this)
 {
-    SDL_Mouse *mouse = SDL_GetMouse();
-    if (mouse) {
-        if (mouse->internal) {
-            SDL_free(mouse->internal);
-            mouse->internal = NULL;
-        }
-    }
 }
 
 #endif // SDL_VIDEO_DRIVER_COCOA