diff --git a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs index 2af3f977..ea0f2433 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs @@ -55,7 +55,7 @@ namespace OpenTK.Platform.SDL2 } } - readonly List joysticks = new List(); + readonly List joysticks = new List(4); readonly Dictionary controllers = new Dictionary(); IList joysticks_readonly; @@ -131,16 +131,18 @@ namespace OpenTK.Platform.SDL2 case EventType.JOYDEVICEADDED: { // Make sure we have enough space to store this instance - if (joysticks.Count <= id) + if (joysticks.Capacity <= id) { - joysticks.Capacity = OpenTK.MathHelper.NextPowerOfTwo(id); + joysticks.Capacity = OpenTK.MathHelper.NextPowerOfTwo(id + 1); + for (int i = joysticks.Count; i < joysticks.Capacity; i++) + joysticks.Add(null); // Expand the joysticks list } IntPtr handle = SDL.JoystickOpen(id); if (handle != IntPtr.Zero) { JoystickDevice joystick = OpenJoystick(id); - if (joysticks != null) + if (joystick != null) { joystick.Details.IsConnected = true; joysticks[id] = joystick;