cocoa: Patched to compile and also handle possible malloc failure.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 18 Jun 2019 16:53:49 -0400
changeset 1288372ab279ffcaa
parent 12882 d629b4244b87
child 12884 e490856ac51c
cocoa: Patched to compile and also handle possible malloc failure.
src/video/cocoa/SDL_cocoamouse.h
src/video/cocoa/SDL_cocoamouse.m
src/video/cocoa/SDL_cocoavideo.m
     1.1 --- a/src/video/cocoa/SDL_cocoamouse.h	Tue Jun 18 13:41:38 2019 -0700
     1.2 +++ b/src/video/cocoa/SDL_cocoamouse.h	Tue Jun 18 16:53:49 2019 -0400
     1.3 @@ -25,7 +25,7 @@
     1.4  
     1.5  #include "SDL_cocoavideo.h"
     1.6  
     1.7 -extern void Cocoa_InitMouse(_THIS);
     1.8 +extern int Cocoa_InitMouse(_THIS);
     1.9  extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
    1.10  extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
    1.11  extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);
     2.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Tue Jun 18 13:41:38 2019 -0700
     2.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Tue Jun 18 16:53:49 2019 -0400
     2.3 @@ -327,13 +327,16 @@
     2.4      return retval;
     2.5  }
     2.6  
     2.7 -void
     2.8 +int
     2.9  Cocoa_InitMouse(_THIS)
    2.10  {
    2.11      SDL_Mouse *mouse = SDL_GetMouse();
    2.12 +    SDL_MouseData *driverdata = (SDL_MouseData*) SDL_calloc(1, sizeof(SDL_MouseData));
    2.13 +    if (driverdata == NULL) {
    2.14 +        return SDL_OutOfMemory();
    2.15 +    }
    2.16  
    2.17 -    mouse->driverdata = SDL_calloc(1, sizeof(SDL_MouseData));
    2.18 -
    2.19 +    mouse->driverdata = driverdata;
    2.20      mouse->CreateCursor = Cocoa_CreateCursor;
    2.21      mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
    2.22      mouse->ShowCursor = Cocoa_ShowCursor;
    2.23 @@ -346,11 +349,12 @@
    2.24  
    2.25      SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
    2.26  
    2.27 -    Cocoa_InitMouseEventTap(mouse->driverdata);
    2.28 +    Cocoa_InitMouseEventTap(driverdata);
    2.29  
    2.30      const NSPoint location =  [NSEvent mouseLocation];
    2.31 -    mouse->driverdata->lastMoveX = location.x;
    2.32 -    mouse->driverdata->lastMoveY = location.y;
    2.33 +    driverdata->lastMoveX = location.x;
    2.34 +    driverdata->lastMoveY = location.y;
    2.35 +    return 0;
    2.36  }
    2.37  
    2.38  void
     3.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Tue Jun 18 13:41:38 2019 -0700
     3.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Tue Jun 18 16:53:49 2019 -0400
     3.3 @@ -168,7 +168,9 @@
     3.4  
     3.5      Cocoa_InitModes(_this);
     3.6      Cocoa_InitKeyboard(_this);
     3.7 -    Cocoa_InitMouse(_this);
     3.8 +    if (Cocoa_InitMouse(_this) < 0) {
     3.9 +        return -1;
    3.10 +    }
    3.11  
    3.12      data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));
    3.13