From ea9dfae43ef54a75d87593ddeb8a4bd658baa1c1 Mon Sep 17 00:00:00 2001 From: Brian Matzon Date: Sun, 10 Jan 2010 22:46:41 +0000 Subject: [PATCH] fix for issue with Cursor that turned out to be a leaking DC --- src/native/windows/org_lwjgl_input_Cursor.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/native/windows/org_lwjgl_input_Cursor.c b/src/native/windows/org_lwjgl_input_Cursor.c index 4c75f206..84d3435e 100644 --- a/src/native/windows/org_lwjgl_input_Cursor.c +++ b/src/native/windows/org_lwjgl_input_Cursor.c @@ -68,6 +68,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateCursor int maskCount = 0; HBITMAP colorBitmap; int x, y; + HDC hDC; jobject handle_buffer = newJavaManagedByteBuffer(env, sizeof(HCURSOR)); int *pixels; @@ -85,8 +86,10 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateCursor bitmapInfo.bmiHeader.biBitCount = 24; bitmapInfo.bmiHeader.biCompression = BI_RGB; + + hDC = GetDC(NULL); - colorDIB = CreateDIBSection(GetDC(NULL), (BITMAPINFO*)&(bitmapInfo), + colorDIB = CreateDIBSection(hDC, (BITMAPINFO*)&(bitmapInfo), DIB_RGB_COLORS, (void*)&(ptrCursorImage), NULL, 0); @@ -94,6 +97,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateCursor dstPtr = ptrCursorImage; if (!dstPtr) { throwException(env, "Could not allocate DIB section."); + ReleaseDC(NULL, hDC); return NULL; } for (y = 0; y < height; y++ ) { @@ -107,7 +111,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateCursor } } - colorBitmap = CreateDIBitmap(GetDC(NULL), + colorBitmap = CreateDIBitmap(hDC, (BITMAPINFOHEADER*)&bitmapInfo.bmiHeader, CBM_INIT, (void *)ptrCursorImage, @@ -148,6 +152,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateCursor DeleteObject(colorBitmap); DeleteObject(cursorMask); free(maskPixels); + ReleaseDC(NULL, hDC); cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer); *cursor_handle = cursor;