src/macosx/classes/sun/lwawt/macosx/CCustomCursor.java

Print this page

        

@@ -34,10 +34,11 @@
         final Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
         return sMaxCursorSize = new Dimension(bounds.width / 2, bounds.height / 2);
     }
 
     Image fImage;
+    private boolean isImageOk = false;
     Point fHotspot;
 
     public CCustomCursor(final Image cursor, final Point hotSpot, final String name) throws IndexOutOfBoundsException, HeadlessException {
         super(name);
         fImage = cursor;

@@ -62,10 +63,13 @@
         // If the image is invalid, the cursor will be hidden (made completely
         // transparent). In this case, getBestCursorSize() will adjust negative w and h,
         // but we need to set the hotspot inside the image here.
         if (tracker.isErrorAny() || width < 0 || height < 0) {
             fHotspot.x = fHotspot.y = 0;
+            isImageOk = false;
+        } else {
+            isImageOk = true;
         }
 
         // Scale image to nearest supported size
         final Dimension nativeSize = toolkit.getBestCursorSize(width, height);
         if (nativeSize.width != width || nativeSize.height != height) {

@@ -108,21 +112,32 @@
 
     // Called from native when the cursor is set
     // Returns long array of [NSImage ptr, x hotspot, y hotspot]
     CImage fCImage;
     long getImageData() {
-        if (fCImage == null) {
+        if (fCImage != null) {
+            return fCImage.ptr;
+        }
+
+        if (isImageOk) {
             try {
                 fCImage = CImage.getCreator().createFromImage(fImage);
+
+                if (fCImage == null) {
+                    isImageOk = false;
+                    return 0L;
+                } else {
+                    return fCImage.ptr;
+                }
             } catch (IllegalArgumentException iae) {
                 // Silently return null - we want to hide cursor by providing an empty
                 // ByteArray or just null
                 return 0L;
             }
         }
 
-        return fCImage.ptr;
+        return 0L;
     }
 
     Point getHotSpot() {
         return fHotspot;
     }