From 31ce400a7e206e41564e35227570d8ff90cdeac6 Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Sun, 22 Dec 2013 23:55:46 +0100 Subject: [PATCH] Fixed expansion of joysticks collection --- Source/OpenTK/Platform/SDL2/Sdl2JoystickDriver.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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;