mirror of
https://github.com/Ryujinx/SDL2-CS.git
synced 2025-03-04 22:19:44 +00:00
Fix Win32 UTF8 marshaling
This commit is contained in:
parent
f29dbb7e4d
commit
2e9752838d
|
@ -80,7 +80,7 @@ namespace SDL2
|
||||||
throw new ArgumentException("ManagedObj must be a string.", "ManagedObj");
|
throw new ArgumentException("ManagedObj must be a string.", "ManagedObj");
|
||||||
}
|
}
|
||||||
var bytes = Encoding.UTF8.GetBytes(str);
|
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);
|
Marshal.Copy(bytes, 0, mem, bytes.Length);
|
||||||
((byte*)mem)[bytes.Length] = 0;
|
((byte*)mem)[bytes.Length] = 0;
|
||||||
return mem;
|
return mem;
|
||||||
|
@ -94,7 +94,7 @@ namespace SDL2
|
||||||
{
|
{
|
||||||
if (!_leaveAllocated)
|
if (!_leaveAllocated)
|
||||||
{
|
{
|
||||||
Marshal.FreeHGlobal(pNativeData);
|
SDL.SDL_free(pNativeData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,14 @@ namespace SDL2
|
||||||
SDL_TRUE = 1
|
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
|
#endregion
|
||||||
|
|
||||||
#region SDL_rwops.h
|
#region SDL_rwops.h
|
||||||
|
|
Loading…
Reference in a new issue