cocoa: Patched to compile and also handle possible malloc failure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/src/video/cocoa/SDL_cocoamouse.h b/src/video/cocoa/SDL_cocoamouse.h
index b9d8196..0d73a97 100644
--- a/src/video/cocoa/SDL_cocoamouse.h
+++ b/src/video/cocoa/SDL_cocoamouse.h
@@ -25,7 +25,7 @@
#include "SDL_cocoavideo.h"
-extern void Cocoa_InitMouse(_THIS);
+extern int Cocoa_InitMouse(_THIS);
extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index c257be0..937057d 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -327,13 +327,16 @@ Cocoa_GetGlobalMouseState(int *x, int *y)
return retval;
}
-void
+int
Cocoa_InitMouse(_THIS)
{
SDL_Mouse *mouse = SDL_GetMouse();
+ SDL_MouseData *driverdata = (SDL_MouseData*) SDL_calloc(1, sizeof(SDL_MouseData));
+ if (driverdata == NULL) {
+ return SDL_OutOfMemory();
+ }
- mouse->driverdata = SDL_calloc(1, sizeof(SDL_MouseData));
-
+ mouse->driverdata = driverdata;
mouse->CreateCursor = Cocoa_CreateCursor;
mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
mouse->ShowCursor = Cocoa_ShowCursor;
@@ -346,11 +349,12 @@ Cocoa_InitMouse(_THIS)
SDL_SetDefaultCursor(Cocoa_CreateDefaultCursor());
- Cocoa_InitMouseEventTap(mouse->driverdata);
+ Cocoa_InitMouseEventTap(driverdata);
const NSPoint location = [NSEvent mouseLocation];
- mouse->driverdata->lastMoveX = location.x;
- mouse->driverdata->lastMoveY = location.y;
+ driverdata->lastMoveX = location.x;
+ driverdata->lastMoveY = location.y;
+ return 0;
}
void
diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m
index 036b3d2..c8f32d3 100644
--- a/src/video/cocoa/SDL_cocoavideo.m
+++ b/src/video/cocoa/SDL_cocoavideo.m
@@ -168,7 +168,9 @@ Cocoa_VideoInit(_THIS)
Cocoa_InitModes(_this);
Cocoa_InitKeyboard(_this);
- Cocoa_InitMouse(_this);
+ if (Cocoa_InitMouse(_this) < 0) {
+ return -1;
+ }
data->allow_spaces = ((floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) && SDL_GetHintBoolean(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, SDL_TRUE));