From 6ce1c2d8ff4fad9d608513857847c079d01834d2 Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Tue, 5 Aug 2025 14:38:08 +0200 Subject: [PATCH] Initialization handles without creating a Cursor instance In win32_getHandle, a new cursor instance is created to retrieve the OS handle. With this change, we are able to safely retrieve the handle without creating a cursor instance. --- .../win32/org/eclipse/swt/graphics/Cursor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java index 33b9fc2042b..72ce9e1a23c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Cursor.java @@ -444,12 +444,12 @@ public static Long win32_getHandle (Cursor cursor, int zoom) { source = DPIUtil.scaleImageData(cursor.device, cursor.source, zoom, DEFAULT_ZOOM); } if (cursor.isIcon) { - Cursor newCursor = new Cursor(cursor.device, source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom)); - cursor.setHandleForZoomLevel(newCursor.handle, zoom); + long handle = setupCursorFromImageData(cursor.getDevice(), source, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom)); + cursor.setHandleForZoomLevel(handle, zoom); } else { - ImageData mask = DPIUtil.scaleImageData(cursor.device, cursor.mask, zoom, DEFAULT_ZOOM); - Cursor newCursor = new Cursor(cursor.device, source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom)); - cursor.setHandleForZoomLevel(newCursor.handle, zoom); + ImageData mask = DPIUtil.scaleImageData(cursor.getDevice(), cursor.mask, zoom, DEFAULT_ZOOM); + long handle = setupCursorFromImageData(source, mask, Win32DPIUtils.pointToPixel(cursor.hotspotX, zoom), Win32DPIUtils.pointToPixel(cursor.hotspotY, zoom)); + cursor.setHandleForZoomLevel(handle, zoom); } } return cursor.zoomLevelToHandle.get(zoom);