diff --git a/src/LPUtf8StrMarshaler.cs b/src/LPUtf8StrMarshaler.cs index bc28039..ca91f74 100644 --- a/src/LPUtf8StrMarshaler.cs +++ b/src/LPUtf8StrMarshaler.cs @@ -80,7 +80,7 @@ namespace SDL2 throw new ArgumentException("ManagedObj must be a string.", "ManagedObj"); } var bytes = Encoding.UTF8.GetBytes(str); - var mem = Marshal.AllocHGlobal(bytes.Length + 1); + var mem = SDL.SDL_malloc((IntPtr) bytes.Length + 1); Marshal.Copy(bytes, 0, mem, bytes.Length); ((byte*)mem)[bytes.Length] = 0; return mem; @@ -94,7 +94,7 @@ namespace SDL2 { if (!_leaveAllocated) { - Marshal.FreeHGlobal(pNativeData); + SDL.SDL_free(pNativeData); } } diff --git a/src/SDL2.cs b/src/SDL2.cs index 74e3564..99323f1 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -60,6 +60,14 @@ namespace SDL2 SDL_TRUE = 1 } + /* malloc/free are used by the marshaler! -flibit */ + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr SDL_malloc(IntPtr size); + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void SDL_free(IntPtr memblock); + #endregion #region SDL_rwops.h