diff --git a/src/Input/Gamepad.cs b/src/Input/Gamepad.cs index 7b53b3f9..14c9982b 100644 --- a/src/Input/Gamepad.cs +++ b/src/Input/Gamepad.cs @@ -195,6 +195,20 @@ namespace MoonWorks.Input }; } + public void Register(IntPtr handle) + { + Handle = handle; + + IntPtr joystickHandle = SDL.SDL_GameControllerGetJoystick(Handle); + JoystickInstanceID = SDL.SDL_JoystickInstanceID(joystickHandle); + } + + public void Unregister() + { + Handle = IntPtr.Zero; + JoystickInstanceID = -1; + } + internal void Update() { AnyPressed = false; diff --git a/src/Input/Input.cs b/src/Input/Input.cs index 088fa43e..5ac31dfe 100644 --- a/src/Input/Input.cs +++ b/src/Input/Input.cs @@ -95,7 +95,7 @@ namespace MoonWorks.Input } else { - gamepads[slot].Handle = openResult; + gamepads[slot].Register(openResult); System.Console.WriteLine($"Gamepad added to slot {slot}!"); } return; @@ -112,7 +112,7 @@ namespace MoonWorks.Input if (joystickInstanceID == gamepads[slot].JoystickInstanceID) { SDL.SDL_GameControllerClose(gamepads[slot].Handle); - gamepads[slot].Handle = IntPtr.Zero; + gamepads[slot].Unregister(); System.Console.WriteLine($"Removing gamepad from slot {slot}!"); return; }