Skip to content

Commit 9f7e52b

Browse files
committed
Add a temporary workaround for the CHIP
Reported this to the CHIP team: Seeing some odd exception from deep within Java's awt classes ("Width (0) and height (0) must be non-zero"). This is triggered because the libX11 function XQueryBestCursor is returning a width and height of zero, which seems to be a bug. I am guessing that this will also pop up with other Java applications. This makes things work on the CHIP w/ OS image 4.4 and latest packages. I also tested on OS X, but I am not familiar enough with the Tweak Mode to say for sure.
1 parent 4ae8946 commit 9f7e52b

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

core/src/processing/awt/PSurfaceAWT.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,13 @@ public void setCursor(PImage img, int x, int y) {
14821482
// Don't set cursorType, instead use cursorType to save the last
14831483
// regular cursor type used for when cursor() is called.
14841484
//cursor_type = Cursor.CUSTOM_CURSOR;
1485+
1486+
// this is a temporary workaround for the CHIP, will be removed
1487+
Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(img.width, img.height);
1488+
if (cursorSize.width == 0 || cursorSize.height == 0) {
1489+
return;
1490+
}
1491+
14851492
Cursor cursor =
14861493
canvas.getToolkit().createCustomCursor((Image) img.getNative(),
14871494
new Point(x, y),
@@ -1511,8 +1518,14 @@ public void hideCursor() {
15111518
if (invisibleCursor == null) {
15121519
BufferedImage cursorImg =
15131520
new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
1514-
invisibleCursor =
1515-
canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1521+
// this is a temporary workaround for the CHIP, will be removed
1522+
Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
1523+
if (cursorSize.width == 0 || cursorSize.height == 0) {
1524+
invisibleCursor = Cursor.getDefaultCursor();
1525+
} else {
1526+
invisibleCursor =
1527+
canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1528+
}
15161529
}
15171530
canvas.setCursor(invisibleCursor);
15181531
cursorVisible = false;

java/src/processing/mode/java/pdex/JavaTextAreaPainter.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.awt.Color;
2727
import java.awt.Cursor;
28+
import java.awt.Dimension;
2829
import java.awt.Font;
2930
import java.awt.Graphics;
3031
import java.awt.Graphics2D;
@@ -401,8 +402,16 @@ public String getToolTipText(MouseEvent evt) {
401402

402403
int cursorType;
403404
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
404-
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
405-
405+
Cursor blankCursor;
406+
// this is a temporary workaround for the CHIP, will be removed
407+
{
408+
Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
409+
if (cursorSize.width == 0 || cursorSize.height == 0) {
410+
blankCursor = Cursor.getDefaultCursor();
411+
} else {
412+
blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
413+
}
414+
}
406415

407416
@Override
408417
synchronized public void paint(Graphics gfx) {

0 commit comments

Comments
 (0)