some cleanup
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SDL3_TestingSuite.SDL3;
|
||||
|
||||
public unsafe static class ImGuiUserData<T> where T : class
|
||||
{
|
||||
public static void* Store(T value)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(value, GCHandleType.Normal);
|
||||
return (void*)GCHandle.ToIntPtr(handle);
|
||||
}
|
||||
|
||||
public static T? Get(void* ptr)
|
||||
{
|
||||
if (ptr == null)
|
||||
return null;
|
||||
|
||||
GCHandle handle = GCHandle.FromIntPtr((nint)ptr);
|
||||
return (T?)handle.Target;
|
||||
}
|
||||
|
||||
public static void Free(void* ptr)
|
||||
{
|
||||
if (ptr == null)
|
||||
return;
|
||||
|
||||
GCHandle handle = GCHandle.FromIntPtr((nint)ptr);
|
||||
|
||||
if (handle.IsAllocated)
|
||||
handle.Free();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user