Browse Source

Prevent double allocations of memory block for quakeparms, and report if allocation of hunk memory fails.

readme
Nico de Poel 5 years ago
parent
commit
e0ce62d2ec
  1. 8
      Assets/Scripts/QuakeParms.cs

8
Assets/Scripts/QuakeParms.cs

@ -29,7 +29,9 @@ public class QuakeParms
public IntPtr ToNativePtr()
{
nativeBlock = Marshal.AllocHGlobal(Marshal.SizeOf<QuakeParms>());
if (nativeBlock == IntPtr.Zero)
nativeBlock = Marshal.AllocHGlobal(Marshal.SizeOf<QuakeParms>());
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()

Loading…
Cancel
Save