[android] Fix: Prevent crash on Bluetooth controller disconnect

This commit is contained in:
edendev 2025-07-04 23:33:32 +00:00
parent d8bfc691d1
commit abbc4fefee
No known key found for this signature in database
GPG key ID: BA8734FD0EE46976

View file

@ -37,8 +37,12 @@ object InputHandler {
} }
fun dispatchGenericMotionEvent(event: MotionEvent): Boolean { fun dispatchGenericMotionEvent(event: MotionEvent): Boolean {
val controllerData = var controllerData = androidControllers[event.device.controllerNumber]
androidControllers[event.device.controllerNumber] ?: return false if (controllerData == null) {
updateControllerData()
controllerData = androidControllers[event.device.controllerNumber] ?: return false
}
event.device.motionRanges.forEach { event.device.motionRanges.forEach {
NativeInput.onGamePadAxisEvent( NativeInput.onGamePadAxisEvent(
controllerData.getGUID(), controllerData.getGUID(),
@ -48,7 +52,7 @@ object InputHandler {
) )
} }
return true return true
} }
fun getDevices(): Map<Int, YuzuPhysicalDevice> { fun getDevices(): Map<Int, YuzuPhysicalDevice> {
val gameControllerDeviceIds = mutableMapOf<Int, YuzuPhysicalDevice>() val gameControllerDeviceIds = mutableMapOf<Int, YuzuPhysicalDevice>()