Browse Source
macOS native: fix destructors accessing freed .NET objects
pull/12248/head
Julien Lebosquain
3 years ago
No known key found for this signature in database
GPG Key ID: 1833CAD10ACC46FD
4 changed files with
34 additions and
2 deletions
-
native/Avalonia.Native/src/OSX/app.mm
-
native/Avalonia.Native/src/OSX/common.h
-
native/Avalonia.Native/src/OSX/main.mm
-
src/Avalonia.Native/AvaloniaNativePlatform.cs
|
|
|
@ -2,6 +2,7 @@ |
|
|
|
#include "AvnString.h" |
|
|
|
@interface AvnAppDelegate : NSObject<NSApplicationDelegate> |
|
|
|
-(AvnAppDelegate* _Nonnull) initWithEvents: (IAvnApplicationEvents* _Nonnull) events; |
|
|
|
-(void) releaseEvents; |
|
|
|
@end |
|
|
|
|
|
|
|
NSApplicationActivationPolicy AvnDesiredActivationPolicy = NSApplicationActivationPolicyRegular; |
|
|
|
@ -15,6 +16,11 @@ ComPtr<IAvnApplicationEvents> _events; |
|
|
|
return self; |
|
|
|
} |
|
|
|
|
|
|
|
- (void)releaseEvents |
|
|
|
{ |
|
|
|
_events = nil; |
|
|
|
} |
|
|
|
|
|
|
|
- (void)applicationWillFinishLaunching:(NSNotification *)notification |
|
|
|
{ |
|
|
|
if([[NSApplication sharedApplication] activationPolicy] != AvnDesiredActivationPolicy) |
|
|
|
@ -105,6 +111,18 @@ extern void InitializeAvnApp(IAvnApplicationEvents* events, bool disableAppDeleg |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
extern void ReleaseAvnAppEvents() |
|
|
|
{ |
|
|
|
NSApplication* app = [AvnApplication sharedApplication]; |
|
|
|
id delegate = [app delegate]; |
|
|
|
if ([delegate isMemberOfClass:[AvnAppDelegate class]]) |
|
|
|
{ |
|
|
|
AvnAppDelegate* avnDelegate = delegate; |
|
|
|
[avnDelegate releaseEvents]; |
|
|
|
[app setDelegate:nil]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
HRESULT AvnApplicationCommands::HideApp() |
|
|
|
{ |
|
|
|
START_COM_CALL; |
|
|
|
|
|
|
|
@ -38,6 +38,7 @@ extern IAvnMenu* GetAppMenu (); |
|
|
|
extern NSMenuItem* GetAppMenuItem (); |
|
|
|
|
|
|
|
extern void InitializeAvnApp(IAvnApplicationEvents* events, bool disableAppDelegate); |
|
|
|
extern void ReleaseAvnAppEvents(); |
|
|
|
extern NSApplicationActivationPolicy AvnDesiredActivationPolicy; |
|
|
|
extern NSPoint ToNSPoint (AvnPoint p); |
|
|
|
extern NSRect ToNSRect (AvnRect r); |
|
|
|
|
|
|
|
@ -197,6 +197,13 @@ class AvaloniaNative : public ComSingleObject<IAvaloniaNativeFactory, &IID_IAval |
|
|
|
|
|
|
|
public: |
|
|
|
FORWARD_IUNKNOWN() |
|
|
|
|
|
|
|
virtual ~AvaloniaNative() override { |
|
|
|
ReleaseAvnAppEvents(); |
|
|
|
_deallocator = nullptr; |
|
|
|
_dispatcher = nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
virtual HRESULT Initialize(IAvnGCHandleDeallocatorCallback* deallocator, |
|
|
|
IAvnApplicationEvents* events, |
|
|
|
IAvnDispatcher* dispatcher) override |
|
|
|
|
|
|
|
@ -3,9 +3,7 @@ using System.Runtime.InteropServices; |
|
|
|
using Avalonia.Controls.Platform; |
|
|
|
using Avalonia.Input; |
|
|
|
using Avalonia.Input.Platform; |
|
|
|
using Avalonia.MicroCom; |
|
|
|
using Avalonia.Native.Interop; |
|
|
|
using Avalonia.OpenGL; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.Rendering; |
|
|
|
using Avalonia.Rendering.Composition; |
|
|
|
@ -163,6 +161,14 @@ namespace Avalonia.Native |
|
|
|
|
|
|
|
|
|
|
|
Compositor = new Compositor(_platformGraphics, true); |
|
|
|
|
|
|
|
Dispatcher.UIThread.ShutdownFinished += OnDispatcherShutdownFinished; |
|
|
|
} |
|
|
|
|
|
|
|
private void OnDispatcherShutdownFinished(object? sender, EventArgs e) |
|
|
|
{ |
|
|
|
Dispatcher.UIThread.ShutdownFinished -= OnDispatcherShutdownFinished; |
|
|
|
_factory.Dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
public ITrayIconImpl CreateTrayIcon() |
|
|
|
|