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!");
}
try (Memory memory = new Memory(bytes.length)) {
memory.write(0, bytes, 0, bytes.length);
SDL_RWops rw = SDL_RWFromConstMem(memory, (int) memory.size());
int count = SDL_GameControllerAddMappingsFromRW(rw, 1);
if (count < 1) {
Log.LOGGER.error("SDL2 failed to load gamepad mappings!");
if (SDL2NativesManager.isLoaded()) {
try (Memory memory = new Memory(bytes.length)) {
memory.write(0, bytes, 0, bytes.length);
SDL_RWops rw = SDL_RWFromConstMem(memory, (int) memory.size());
int count = SDL_GameControllerAddMappingsFromRW(rw, 1);
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);
}
}