From d396992cc5f25cdc3342e57357e8e628c71cb5b2 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 27 Oct 2006 06:27:58 +0000 Subject: [PATCH] Fixed potential NPE from Cursor.getCapabilities() --- src/java/org/lwjgl/input/Cursor.java | 5 ++++- src/java/org/lwjgl/input/Keyboard.java | 2 ++ src/java/org/lwjgl/input/Mouse.java | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/java/org/lwjgl/input/Cursor.java b/src/java/org/lwjgl/input/Cursor.java index 972f49a8..e8c6e401 100644 --- a/src/java/org/lwjgl/input/Cursor.java +++ b/src/java/org/lwjgl/input/Cursor.java @@ -141,7 +141,10 @@ public class Cursor { * @return A bit mask with native cursor capabilities. */ public static int getCapabilities() { - return Mouse.getImplementation().getNativeCursorCapabilities(); + if (Mouse.getImplementation() != null) + return Mouse.getImplementation().getNativeCursorCapabilities(); + else + return Mouse.createImplementation().getNativeCursorCapabilities(); } /** diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java index a91ef40c..a0f3c75e 100644 --- a/src/java/org/lwjgl/input/Keyboard.java +++ b/src/java/org/lwjgl/input/Keyboard.java @@ -307,6 +307,8 @@ public class Keyboard { * @throws LWJGLException if the keyboard could not be created for any reason */ public static void create() throws LWJGLException { + if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); + create(Mouse.createImplementation()); } diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java index 4416da7b..b308e2fa 100644 --- a/src/java/org/lwjgl/input/Mouse.java +++ b/src/java/org/lwjgl/input/Mouse.java @@ -225,8 +225,6 @@ public class Mouse { } static InputImplementation createImplementation() { - if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); - /* Use reflection since we can't make Display.getImplementation * public */ @@ -278,6 +276,8 @@ public class Mouse { * @throws LWJGLException if the mouse could not be created for any reason */ public static void create() throws LWJGLException { + if (!Display.isCreated()) throw new IllegalStateException("Display must be created."); + create(createImplementation()); }