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
public void onInputDeviceRemoved(int deviceId) {
InputDevice inputDevice = this.inputManager.getInputDevice(deviceId);
int sources = inputDevice.getSources();
if ((sources & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD &&
(sources & InputDevice.SOURCE_JOYSTICK) != InputDevice.SOURCE_JOYSTICK) {
return;
}
Ebitenmobileview.onGamepadRemoved(deviceId);
// Do not call inputManager.getInputDevice(), which returns null (#1185).
Ebitenmobileview.onInputDeviceRemoved(deviceId);
}
// 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) {
id := gamepadIDFromDeviceID(deviceID)
delete(gamepads, id)
func OnInputDeviceRemoved(deviceID int) {
if id, ok := deviceIDToGamepadID[deviceID]; ok {
delete(gamepads, id)
delete(deviceIDToGamepadID, deviceID)
}
}