Browse Source

Merge pull request #5324 from AvaloniaUI/unmanaged-blob-fx

Supporess finalization when UnmanagedBlob allocation failed
pull/5331/head
Dan Walmsley 6 years ago
committed by GitHub
parent
commit
5e65954020
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/Shared/PlatformSupport/StandardRuntimePlatform.cs

20
src/Shared/PlatformSupport/StandardRuntimePlatform.cs

@ -49,12 +49,20 @@ namespace Avalonia.Shared.PlatformSupport
public UnmanagedBlob(StandardRuntimePlatform plat, int size) public UnmanagedBlob(StandardRuntimePlatform plat, int size)
{ {
if (size <= 0) try
throw new ArgumentException("Positive number required", nameof(size)); {
_plat = plat; if (size <= 0)
_address = plat.Alloc(size); throw new ArgumentException("Positive number required", nameof(size));
GC.AddMemoryPressure(size); _plat = plat;
Size = size; _address = plat.Alloc(size);
GC.AddMemoryPressure(size);
Size = size;
}
catch
{
GC.SuppressFinalize(this);
throw;
}
#if DEBUG #if DEBUG
_backtrace = Environment.StackTrace; _backtrace = Environment.StackTrace;
lock (_btlock) lock (_btlock)

Loading…
Cancel
Save