1
0
forked from Clones/Controlify

🐛 Fix crash when discovering controllers without SDL

This commit is contained in:
isXander
2023-09-26 23:05:00 +01:00
parent 291975505d
commit 33dd5729ff

View File

@ -434,15 +434,17 @@ public class Controlify implements ControlifyApi {
Log.LOGGER.error("GLFW failed to load gamepad mappings!"); Log.LOGGER.error("GLFW failed to load gamepad mappings!");
} }
try (Memory memory = new Memory(bytes.length)) { if (SDL2NativesManager.isLoaded()) {
memory.write(0, bytes, 0, bytes.length); try (Memory memory = new Memory(bytes.length)) {
SDL_RWops rw = SDL_RWFromConstMem(memory, (int) memory.size()); memory.write(0, bytes, 0, bytes.length);
int count = SDL_GameControllerAddMappingsFromRW(rw, 1); SDL_RWops rw = SDL_RWFromConstMem(memory, (int) memory.size());
if (count < 1) { int count = SDL_GameControllerAddMappingsFromRW(rw, 1);
Log.LOGGER.error("SDL2 failed to load gamepad mappings!"); if (count < 1) {
Log.LOGGER.error("SDL2 failed to load gamepad mappings!");
}
} }
} }
} catch (Exception e) { } catch (Throwable e) {
Log.LOGGER.error("Failed to load gamecontrollerdb.txt", e); Log.LOGGER.error("Failed to load gamecontrollerdb.txt", e);
} }
} }