Skip to content

Commit

Permalink
Working exception dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
danwalmsley committed Jan 19, 2020
1 parent 69c0521 commit c3fb152
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions native/Avalonia.Native/inc/avalonia-native.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ AVNCOM(IAvnPlatformThreadingInterface, 0b) : IUnknown
// Can't pass int* to sharpgentools for some reason
virtual void Signal(int priority) = 0;
virtual IUnknown* StartTimer(int priority, int ms, IAvnActionCallback* callback) = 0;
virtual HRESULT TerminateApp () = 0;
};

AVNCOM(IAvnSystemDialogEvents, 0c) : IUnknown
Expand Down
6 changes: 6 additions & 0 deletions native/Avalonia.Native/src/OSX/platformthreading.mm
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ virtual void Signal(int priority) override
return new TimerWrapper(callback, ms);
}
}

virtual HRESULT TerminateApp () override
{
[NSApp stop:0];
return S_OK;
}
};

@implementation Signaler
Expand Down
10 changes: 6 additions & 4 deletions src/Avalonia.Native/CallbackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Runtime.ExceptionServices;
using SharpGen.Runtime;
using Avalonia.Platform;

namespace Avalonia.Native
{
Expand Down Expand Up @@ -80,11 +81,12 @@ protected virtual void Destroyed()

public void RaiseException(Exception e)
{
var threadingInterface = AvaloniaLocator.Current.GetService<PlatformThreadingInterface>();

threadingInterface.TerminateNativeApp();
if (AvaloniaLocator.Current.GetService<IPlatformThreadingInterface>() is PlatformThreadingInterface threadingInterface)
{
threadingInterface.TerminateNativeApp();

threadingInterface.DispatchException(ExceptionDispatchInfo.Capture(e));
threadingInterface.DispatchException(ExceptionDispatchInfo.Capture(e));
}
}
}
}
2 changes: 1 addition & 1 deletion src/Avalonia.Native/PlatformThreadingInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void DispatchException (ExceptionDispatchInfo exceptionInfo)

public void TerminateNativeApp()
{

_native.TerminateApp();
}

public void Signal(DispatcherPriority priority)
Expand Down

0 comments on commit c3fb152

Please sign in to comment.