diff --git a/Assets/Scripts/QuakeParms.cs b/Assets/Scripts/QuakeParms.cs index f983db9..7d5c845 100644 --- a/Assets/Scripts/QuakeParms.cs +++ b/Assets/Scripts/QuakeParms.cs @@ -29,7 +29,9 @@ public class QuakeParms public IntPtr ToNativePtr() { - nativeBlock = Marshal.AllocHGlobal(Marshal.SizeOf()); + if (nativeBlock == IntPtr.Zero) + nativeBlock = Marshal.AllocHGlobal(Marshal.SizeOf()); + Marshal.StructureToPtr(this, nativeBlock, false); return nativeBlock; } @@ -48,6 +50,10 @@ public class QuakeParms { memSize = memorySize; memBase = Marshal.AllocHGlobal(memorySize); + if (memBase == IntPtr.Zero) + { + throw new OutOfMemoryException($"Could not allocate {memorySize / 1024 / 1024} MB of heap memory!"); + } } public void Destroy()