Skip to content

Commit

Permalink
[ui] filter for cursor styles available on the current system to avoi…
Browse files Browse the repository at this point in the history
…d NPEs in CursorAdapter#dispose (fixes #301)
  • Loading branch information
gliscowo committed Sep 15, 2024
1 parent a2a5b0f commit 5235a88
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/io/wispforest/owo/ui/util/CursorAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public class CursorAdapter {
protected CursorAdapter(long windowHandle) {
this.windowHandle = windowHandle;
for (var style : ACTIVE_STYLES) {
this.cursors.put(style, GLFW.glfwCreateStandardCursor(style.glfw));
var pointer = GLFW.glfwCreateStandardCursor(style.glfw);
if (pointer == 0) continue;

this.cursors.put(style, pointer);
}
}

Expand All @@ -42,7 +45,7 @@ public void applyStyle(CursorStyle style) {
if (style == CursorStyle.NONE) {
GLFW.glfwSetCursor(this.windowHandle, 0);
} else {
GLFW.glfwSetCursor(this.windowHandle, this.cursors.get(style));
GLFW.glfwSetCursor(this.windowHandle, this.cursors.getOrDefault(style, 0L));
}
this.lastCursorStyle = style;
}
Expand Down

0 comments on commit 5235a88

Please sign in to comment.