diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index 865bb362..d7d13ee2 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -48,7 +48,6 @@ import org.lwjgl.LWJGLException; import org.lwjgl.input.Keyboard; final class LinuxDisplay implements DisplayImplementation { - private static final int CURSOR_HANDLE_SIZE = 8; // private static final int PBUFFER_HANDLE_SIZE = 24; private static final int NUM_BUTTONS = 3; @@ -359,16 +358,14 @@ final class LinuxDisplay implements DisplayImplementation { return Keyboard.STATE_UNKNOWN; } - private static native void nCreateCursor(ByteBuffer handle, 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 ByteBuffer nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { lockAWT(); try { incDisplay(); try { - ByteBuffer handle = BufferUtils.createByteBuffer(CURSOR_HANDLE_SIZE); - nCreateCursor(handle, width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1); - return handle; + return nCreateCursor(width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1); } catch (LWJGLException e) { decDisplay(); throw e; diff --git a/src/native/linux/org_lwjgl_input_Cursor.c b/src/native/linux/org_lwjgl_input_Cursor.c index bf7690c4..47746cda 100644 --- a/src/native/linux/org_lwjgl_input_Cursor.c +++ b/src/native/linux/org_lwjgl_input_Cursor.c @@ -77,12 +77,13 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetMaxCursorSize return width_return > height_return ? height_return : width_return; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor - (JNIEnv *env, jclass clazz, jobject handle_buffer, 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) +JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor + (JNIEnv *env, jclass clazz, 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) { - if ((*env)->GetDirectBufferCapacity(env, handle_buffer) < sizeof(Cursor)) { - throwException(env, "Handle buffer not large enough"); - return; + jobject handle_buffer = newJavaManagedByteBuffer(env, sizeof(Cursor)); + if (handle_buffer == NULL) { + throwException(env, "Could not allocate handle buffer"); + return NULL; } const int *delays = NULL; if (delay_buffer != NULL) @@ -92,7 +93,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor XcursorImages *cursor_images = XcursorImagesCreate(num_images); if (cursor_images == NULL) { throwException(env, "Could not allocate cursor."); - return; + return NULL; } cursor_images->nimage = num_images; int i; @@ -108,6 +109,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateCursor Cursor *cursor = (Cursor *)(*env)->GetDirectBufferAddress(env, handle_buffer); *cursor = XcursorImagesLoadCursor(getDisplay(), cursor_images); XcursorImagesDestroy(cursor_images); + return handle_buffer; } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nDestroyCursor