diff --git a/native/Avalonia.Native/src/OSX/rendertarget.mm b/native/Avalonia.Native/src/OSX/rendertarget.mm
index 00b6dab219..b2d4341bb9 100644
--- a/native/Avalonia.Native/src/OSX/rendertarget.mm
+++ b/native/Avalonia.Native/src/OSX/rendertarget.mm
@@ -111,7 +111,11 @@
if(_renderbuffer != 0)
glDeleteRenderbuffers(1, &_renderbuffer);
}
- CFRelease(surface);
+
+ if(surface != nullptr)
+ {
+ CFRelease(surface);
+ }
}
@end
@@ -145,6 +149,12 @@ static IAvnGlSurfaceRenderTarget* CreateGlRenderTarget(IOSurfaceRenderTarget* ta
}
- (void)resize:(AvnPixelSize)size withScale: (float) scale{
+
+ if(size.Height <= 0)
+ size.Height = 1;
+ if(size.Width <= 0)
+ size.Width = 1;
+
@synchronized (lock) {
if(surface == nil
|| surface->size.Width != size.Width
diff --git a/src/Avalonia.Controls/ContextMenu.cs b/src/Avalonia.Controls/ContextMenu.cs
index 5e17182f3e..fb8080f0d4 100644
--- a/src/Avalonia.Controls/ContextMenu.cs
+++ b/src/Avalonia.Controls/ContextMenu.cs
@@ -246,7 +246,7 @@ namespace Avalonia.Controls
///
/// Opens the menu.
///
- public override void Open() => throw new NotSupportedException();
+ public override void Open() => Open(null);
///
/// Opens a context menu on the specified control.
diff --git a/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs b/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
index 39a3250686..f3a1316c7d 100644
--- a/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/ContextMenuTests.cs
@@ -44,6 +44,55 @@ namespace Avalonia.Controls.UnitTests
}
}
+ [Fact]
+ public void Open_Should_Use_Default_Control()
+ {
+ using (Application())
+ {
+ var sut = new ContextMenu();
+ var target = new Panel
+ {
+ ContextMenu = sut
+ };
+
+ var window = new Window { Content = target };
+ window.ApplyTemplate();
+ window.Presenter.ApplyTemplate();
+
+ bool opened = false;
+
+ sut.MenuOpened += (sender, args) =>
+ {
+ opened = true;
+ };
+
+ sut.Open();
+
+ Assert.True(opened);
+ }
+ }
+
+ [Fact]
+ public void Open_Should_Raise_Exception_If_AlreadyDetached()
+ {
+ using (Application())
+ {
+ var sut = new ContextMenu();
+ var target = new Panel
+ {
+ ContextMenu = sut
+ };
+
+ var window = new Window { Content = target };
+ window.ApplyTemplate();
+ window.Presenter.ApplyTemplate();
+
+ target.ContextMenu = null;
+
+ Assert.ThrowsAny(()=> sut.Open());
+ }
+ }
+
[Fact]
public void Closing_Raises_Single_Closed_Event()
{