mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-16 13:30:35 +00:00
Fix another race in controller detection
This commit is contained in:
@@ -9,6 +9,7 @@ public class NativeGamepad {
|
|||||||
private static ArrayList<NativeGamepadListener> listenerList =
|
private static ArrayList<NativeGamepadListener> listenerList =
|
||||||
new ArrayList<NativeGamepadListener>();
|
new ArrayList<NativeGamepadListener>();
|
||||||
private static boolean running = false;
|
private static boolean running = false;
|
||||||
|
private static boolean initialized = false;
|
||||||
private static Thread deviceThread = null;
|
private static Thread deviceThread = null;
|
||||||
private static Thread eventThread = null;
|
private static Thread eventThread = null;
|
||||||
private static int devicePollingIntervalMs = DEFAULT_DEVICE_POLLING_INTERVAL;
|
private static int devicePollingIntervalMs = DEFAULT_DEVICE_POLLING_INTERVAL;
|
||||||
@@ -16,8 +17,6 @@ public class NativeGamepad {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("gamepad_jni");
|
System.loadLibrary("gamepad_jni");
|
||||||
|
|
||||||
NativeGamepad.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void init();
|
private static native void init();
|
||||||
@@ -55,6 +54,10 @@ public class NativeGamepad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void start() {
|
public static void start() {
|
||||||
|
if (!initialized) {
|
||||||
|
NativeGamepad.init();
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
if (!running) {
|
if (!running) {
|
||||||
startDevicePolling();
|
startDevicePolling();
|
||||||
startEventPolling();
|
startEventPolling();
|
||||||
@@ -75,7 +78,10 @@ public class NativeGamepad {
|
|||||||
throw new IllegalStateException("Cannot release running NativeGamepad");
|
throw new IllegalStateException("Cannot release running NativeGamepad");
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeGamepad.shutdown();
|
if (initialized) {
|
||||||
|
NativeGamepad.shutdown();
|
||||||
|
initialized = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDeviceCount() {
|
public static int getDeviceCount() {
|
||||||
|
|||||||
Reference in New Issue
Block a user