From b3a31034dd63cda5e6f18784f1f193e414e16218 Mon Sep 17 00:00:00 2001 From: js6pak Date: Wed, 25 May 2022 21:29:56 +0200 Subject: [PATCH] Don't crash when xrandr executable is not accessible --- src/java/org/lwjgl/opengl/LinuxDisplay.java | 17 +++++++++++++++++ src/java/org/lwjgl/opengl/XRandR.java | 1 + 2 files changed, 18 insertions(+) diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index 30728fa3e..4de2a1a8e 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -43,6 +43,7 @@ import java.awt.event.FocusEvent; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.nio.ByteOrder; @@ -210,9 +211,25 @@ private static int getBestDisplayModeExtension() { return result; } + private static String findXrandr() { + for (String path : System.getenv("PATH").split(File.pathSeparator)) { + File file = new File(path, "xrandr"); + if (file.isFile() && file.canExecute()) { + return file.getAbsolutePath(); + } + } + + return null; + } + private static boolean isXrandrSupported() { if (Display.getPrivilegedBoolean("LWJGL_DISABLE_XRANDR")) return false; + + if (findXrandr() == null) { + return false; + } + lockAWT(); try { incDisplay(); diff --git a/src/java/org/lwjgl/opengl/XRandR.java b/src/java/org/lwjgl/opengl/XRandR.java index 8e59bb64a..ba9976ff9 100644 --- a/src/java/org/lwjgl/opengl/XRandR.java +++ b/src/java/org/lwjgl/opengl/XRandR.java @@ -146,6 +146,7 @@ private static void populate() { LWJGLUtil.log("Exception in XRandR.populate(): " + e.getMessage()); screens.clear(); current = new Screen[0]; + throw new RuntimeException(e); } }