diff --git a/SDL3-CS.Tests/ObjectHandle.cs b/SDL3-CS.Tests/ObjectHandle.cs index f4c0ae8..7ba497f 100644 --- a/SDL3-CS.Tests/ObjectHandle.cs +++ b/SDL3-CS.Tests/ObjectHandle.cs @@ -28,7 +28,7 @@ namespace SDL.Tests private GCHandle handle; - private readonly bool fromPointer; + private readonly bool canFree; /// /// Wraps the provided object with a , using the given . @@ -38,18 +38,19 @@ namespace SDL.Tests public ObjectHandle(T target, GCHandleType handleType) { handle = GCHandle.Alloc(target, handleType); - fromPointer = false; + canFree = true; } /// /// Recreates an based on the passed . - /// Disposing this object will not free the handle, the original object must be disposed instead. + /// If is true, disposing this object will free the handle. /// - /// Handle. - public ObjectHandle(IntPtr handle) + /// from a previously constructed . + /// Whether this instance owns the underlying . + public ObjectHandle(IntPtr handle, bool ownsHandle = false) { this.handle = GCHandle.FromIntPtr(handle); - fromPointer = true; + canFree = ownsHandle; } /// @@ -86,7 +87,7 @@ namespace SDL.Tests public void Dispose() { - if (!fromPointer && handle.IsAllocated) + if (canFree && handle.IsAllocated) handle.Free(); }