Browse Source

prevent osx crash when closing inside activate.

pull/6199/head
Dan Walmsley 5 years ago
parent
commit
8058a46d26
  1. 18
      native/Avalonia.Native/src/OSX/window.mm

18
native/Avalonia.Native/src/OSX/window.mm

@ -113,9 +113,11 @@ public:
UpdateStyle(); UpdateStyle();
[Window setContentView: StandardContainer]; [Window setContentView: StandardContainer];
[Window setTitle:_lastTitle];
if(ShouldTakeFocusOnShow() && activate) if(ShouldTakeFocusOnShow() && activate)
{ {
[Window orderFront: Window];
[Window makeKeyAndOrderFront:Window]; [Window makeKeyAndOrderFront:Window];
[NSApp activateIgnoringOtherApps:YES]; [NSApp activateIgnoringOtherApps:YES];
} }
@ -123,7 +125,6 @@ public:
{ {
[Window orderFront: Window]; [Window orderFront: Window];
} }
[Window setTitle:_lastTitle];
_shown = true; _shown = true;
@ -180,7 +181,10 @@ public:
{ {
if (Window != nullptr) if (Window != nullptr)
{ {
[Window close]; auto window = Window;
Window = nullptr;
[window close];
} }
return S_OK; return S_OK;
@ -549,6 +553,11 @@ private:
void HideOrShowTrafficLights () void HideOrShowTrafficLights ()
{ {
if (Window == nil)
{
return;
}
for (id subview in Window.contentView.superview.subviews) { for (id subview in Window.contentView.superview.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) { if ([subview isKindOfClass:NSClassFromString(@"NSTitlebarContainerView")]) {
NSView *titlebarView = [subview subviews][0]; NSView *titlebarView = [subview subviews][0];
@ -963,6 +972,11 @@ private:
virtual HRESULT SetWindowState (AvnWindowState state) override virtual HRESULT SetWindowState (AvnWindowState state) override
{ {
if(Window == nullptr)
{
return S_OK;
}
@autoreleasepool @autoreleasepool
{ {
if(_actualWindowState == state) if(_actualWindowState == state)

Loading…
Cancel
Save