diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 172f663c..c646a278 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -441,9 +441,9 @@ final class MacOSXDisplay implements DisplayImplementation { mouse.setCursorPosition(x, y); } } - else { + //else { //MacOSXMouseEventQueue.nWarpCursor(x, y); - } + //} } public void setNativeCursor(Object handle) throws LWJGLException { @@ -520,7 +520,14 @@ final class MacOSXDisplay implements DisplayImplementation { } public void destroyCursor(Object cursor_handle) { + long handle = getCursorHandle(cursor_handle); + // reset current cursor if same + if (currentNativeCursor == handle) { + currentNativeCursor = 0; + } + + MacOSXNativeMouse.destroyCursor(handle); } private static long getCursorHandle(Object cursor_handle) { diff --git a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java index ef204757..6b1af8c3 100644 --- a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java +++ b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java @@ -91,7 +91,7 @@ final class MacOSXNativeMouse extends EventQueue { private static native long nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; - private static native void nDestroyCursor(long cursor_handle) throws LWJGLException; + private static native void nDestroyCursor(long cursor_handle); private static native void nSetCursor(long cursor_handle) throws LWJGLException; @@ -107,12 +107,8 @@ final class MacOSXNativeMouse extends EventQueue { } } - public static void destroyCursor(long cursor_handle) throws LWJGLException { - try { - nDestroyCursor(cursor_handle); - } catch (LWJGLException e) { - throw e; - } + public static void destroyCursor(long cursor_handle) { + nDestroyCursor(cursor_handle); } public static void setCursor(long cursor_handle) throws LWJGLException { diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m b/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m index 9b919f9c..27f07a13 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m @@ -101,9 +101,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nUnregisterMouseL } JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nCreateCursor(JNIEnv *env, jobject _this, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + jlong *bytes = (jint *)(*env)->GetDirectBufferAddress(env, image_buffer) + images_offset; - NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] + NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(jlong *)&bytes pixelsWide:width pixelsHigh:height bitsPerSample:8 @@ -113,20 +115,25 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nCreateCursor(JN colorSpaceName:NSDeviceRGBColorSpace bitmapFormat:NSAlphaNonpremultipliedBitmapFormat bytesPerRow:width*4 - bitsPerPixel:32]; + bitsPerPixel:32] autorelease]; - NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; + NSImage *image = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] autorelease]; [image addRepresentation:bitmap]; NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x_hotspot, y_hotspot)]; + [pool release]; + return (jlong)cursor; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nDestroyCursor(JNIEnv *env, jobject _this, jlong handle) { - // TODO +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nDestroyCursor(JNIEnv *env, jobject _this, jlong cursor_pointer) { + if (cursor_pointer != 0) { + NSCursor *cursor = (NSCursor *)cursor_pointer; + [cursor release]; + } } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nSetCursor(JNIEnv *env, jobject _this, jlong cursor_pointer) {