Fixed memory corruption on string return type marshaling
authorStefanos A <stapostol@gmail.com>
Sun, 15 Dec 2013 19:57:25 +0000 (20:57 +0100)
committerStefanos A <stapostol@gmail.com>
Sun, 15 Dec 2013 19:57:25 +0000 (20:57 +0100)
Source/OpenTK/Platform/SDL2/Sdl2.cs

index 2568dc7020b7bda7b043297d74eb0ff453a64343..9bf07558f91d82bef43cbb0ec5e546b035c6e2d3 100644 (file)
@@ -206,7 +206,14 @@ namespace OpenTK.Platform.SDL2
 
         [SuppressUnmanagedCodeSecurity]
         [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickName", ExactSpelling = true)]
-        public static extern string JoystickName(IntPtr joystick);
+        static extern IntPtr JoystickNameInternal(IntPtr joystick);
+        public static string JoystickName(IntPtr joystick)
+        {
+            unsafe
+            {
+                return new string((sbyte*)JoystickNameInternal(joystick));
+            }
+        }
 
         [SuppressUnmanagedCodeSecurity]
         [DllImport(lib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SDL_JoystickNumAxes", ExactSpelling = true)]