aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-01-03 04:29:38 +0100
committerSven Gothel <[email protected]>2014-01-03 04:29:38 +0100
commitbb5c7496ed92b91dded30816a46b42ff85f37bec (patch)
treea07604394d72291734783e661379b137e2b5b6c9 /src/newt
parent09db30c4a0d9c0f29c47af76238b2abc275301c0 (diff)
Bug 935: NEWT PointerIcon OSX: Safe use of NSCursor handle
Diffstat (limited to 'src/newt')
-rw-r--r--src/newt/native/MacWindow.m17
-rw-r--r--src/newt/native/NewtMacWindow.h4
-rw-r--r--src/newt/native/NewtMacWindow.m37
3 files changed, 42 insertions, 16 deletions
diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m
index 8a466b95e..1be3a6ed5 100644
--- a/src/newt/native/MacWindow.m
+++ b/src/newt/native/MacWindow.m
@@ -340,6 +340,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_DisplayDriver_createPoint
res = [[NSCursor alloc] initWithImage: nsImage hotSpot: hotP];
}
[pool release];
+ DBG_PRINT( "createPointerIcon0 %p\n", res);
return (jlong) (intptr_t) res;
}
@@ -348,7 +349,14 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_DisplayDriver_destroyPoint
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSCursor * c = (NSCursor*) (intptr_t) handle ;
- [c release];
+ if( NULL != c ) {
+ if ( NO == [c isKindOfClass:[NSCursor class]] ) {
+ DBG_PRINT( "destroyPointerIcon0 NSCursor %p - is of invalid type\n", c);
+ } else {
+ DBG_PRINT( "destroyPointerIcon0 %p\n", c);
+ [c release];
+ }
+ }
[pool release];
}
@@ -358,8 +366,11 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_setPointerIco
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NewtMacWindow *mWin = (NewtMacWindow*) (intptr_t) window;
NSCursor * c = (NSCursor*) (intptr_t) handle ;
-
- [mWin setCustomCursor: c];
+ if ( NULL != c && NO == [c isKindOfClass:[NSCursor class]] ) {
+ DBG_PRINT( "setPointerIcon0 NSCursor %p - is of invalid type (1)\n", c);
+ } else {
+ [mWin setPointerIcon: c];
+ }
[pool release];
}
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index ba2e242cf..2728c2201 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -41,7 +41,7 @@
// #define VERBOSE_ON 1
#ifdef VERBOSE_ON
- #define DBG_PRINT(...) NSLog(@ __VA_ARGS__)
+ #define DBG_PRINT(...) NSLog(@ __VA_ARGS__) ; fflush(stderr)
// #define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
#else
#define DBG_PRINT(...)
@@ -151,7 +151,7 @@
- (BOOL) isMouseInside;
- (void) cursorHide:(BOOL)v enter:(int)enterState;
-- (void) setCustomCursor:(NSCursor*)c;
+- (void) setPointerIcon:(NSCursor*)c;
- (void) setMouseVisible:(BOOL)v hasFocus:(BOOL)focus;
- (void) setMouseConfined:(BOOL)v;
- (void) setMousePosition:(NSPoint)p;
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 9f534e319..96965b67a 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -670,15 +670,23 @@ static UniChar CKCH_CharForKeyCode(jshort keyCode) {
}
}
-- (void) setCustomCursor:(NSCursor*)c
+- (void) setPointerIcon:(NSCursor*)c
{
+ DBG_PRINT( "setPointerIcon: mouseInside cursor: %p -> %p (glob %p), mouseInside %d\n", customCursor, c, [NSCursor currentCursor], (int)mouseInside);
if(YES == mouseInside) {
if( NULL != c ) {
- DBG_PRINT( "setCustomCursor push: %p\n", c);
+ DBG_PRINT( "setPointerIcon push: %p\n", c);
[c push];
- } else if( NULL != customCursor && [NSCursor currentCursor] == customCursor ) {
- DBG_PRINT( "setCustomCursor pop: %p\n", customCursor);
- [customCursor pop];
+ } else if( NULL != customCursor ) {
+ if ( NO == [customCursor isKindOfClass:[NSCursor class]] ) {
+ DBG_PRINT( "setPointerIcon0 NSCursor %p - is of invalid type (2)\n", customCursor);
+ if( [NSCursor currentCursor] == customCursor ) {
+ [NSCursor pop];
+ }
+ } else if( [NSCursor currentCursor] == customCursor ) {
+ DBG_PRINT( "setPointerIcon pop: %p\n", customCursor);
+ [customCursor pop];
+ }
}
}
customCursor = c;
@@ -688,12 +696,19 @@ static UniChar CKCH_CharForKeyCode(jshort keyCode) {
{
DBG_PRINT( "cursorHide: %d -> %d, enter %d\n", cursorIsHidden, v, enterState);
if( NULL != customCursor ) {
- if( 1 == enterState && [NSCursor currentCursor] != customCursor ) {
- DBG_PRINT( "cursorHide.customCursor push: %p\n", customCursor);
- [customCursor push];
- } else if( -1 == enterState && [NSCursor currentCursor] == customCursor ) {
- DBG_PRINT( "cursorHide.customCursor pop: %p\n", customCursor);
- [customCursor pop];
+ if ( NO == [customCursor isKindOfClass:[NSCursor class]] ) {
+ DBG_PRINT( "setPointerIcon0 NSCursor %p - is of invalid type (3)\n", customCursor);
+ if( [NSCursor currentCursor] == customCursor ) {
+ [NSCursor pop];
+ }
+ } else {
+ if( 1 == enterState && [NSCursor currentCursor] != customCursor ) {
+ DBG_PRINT( "cursorHide.PointerIcon push: %p\n", customCursor);
+ [customCursor push];
+ } else if( -1 == enterState && [NSCursor currentCursor] == customCursor ) {
+ DBG_PRINT( "cursorHide.PointerIcon pop: %p\n", customCursor);
+ [customCursor pop];
+ }
}
}
if(v) {