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 2568dc7..9bf0755 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)]