cmd/ebitenmobileview: Bug fix: Crash when removing a gamepad

Fixes #1185
This commit is contained in:
Hajime Hoshi 2020-06-09 23:34:07 +09:00
parent a2b97be266
commit f350b03232
3 changed files with 8 additions and 11 deletions

View File

@ -675,13 +675,8 @@ public class EbitenView extends ViewGroup implements InputManager.InputDeviceLis
@Override @Override
public void onInputDeviceRemoved(int deviceId) { public void onInputDeviceRemoved(int deviceId) {
InputDevice inputDevice = this.inputManager.getInputDevice(deviceId); // Do not call inputManager.getInputDevice(), which returns null (#1185).
int sources = inputDevice.getSources(); Ebitenmobileview.onInputDeviceRemoved(deviceId);
if ((sources & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD &&
(sources & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK) {
return;
}
Ebitenmobileview.onGamepadRemoved(deviceId);
} }
// suspendGame suspends the game. // suspendGame suspends the game.

File diff suppressed because one or more lines are too long

View File

@ -315,7 +315,9 @@ func OnGamepadAdded(deviceID int, name string, buttonNum int, axisNum int, descr
} }
} }
func OnGamepadRemoved(deviceID int) { func OnInputDeviceRemoved(deviceID int) {
id := gamepadIDFromDeviceID(deviceID) if id, ok := deviceIDToGamepadID[deviceID]; ok {
delete(gamepads, id) delete(gamepads, id)
delete(deviceIDToGamepadID, deviceID)
}
} }