Skip to content

Commit

Permalink
Add methods for dispatching exceptions on osx.
Browse files Browse the repository at this point in the history
  • Loading branch information
danwalmsley committed Jan 19, 2020
1 parent c357558 commit 69c0521
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/Avalonia.Native/CallbackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ protected virtual void Destroyed()

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

PlatformThreadingInterface.s_exceptionDispatchInfo = exceptionInfo;
threadingInterface.TerminateNativeApp();

threadingInterface.DispatchException(ExceptionDispatchInfo.Capture(e));
}
}
}
19 changes: 13 additions & 6 deletions src/Avalonia.Native/PlatformThreadingInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace Avalonia.Native
{
public class PlatformThreadingInterface : IPlatformThreadingInterface
{
public static ExceptionDispatchInfo s_exceptionDispatchInfo;

class TimerCallback : CallbackBase, IAvnActionCallback
{
readonly Action _tick;
Expand Down Expand Up @@ -46,6 +44,7 @@ public void Signaled(int priority, bool priorityContainsMeaningfulValue)
}

readonly IAvnPlatformThreadingInterface _native;
private ExceptionDispatchInfo _exceptionDispatchInfo;

public PlatformThreadingInterface(IAvnPlatformThreadingInterface native)
{
Expand Down Expand Up @@ -86,15 +85,23 @@ public void RunLoop(CancellationToken cancellationToken)
}
}

if(s_exceptionDispatchInfo != null)
if(_exceptionDispatchInfo != null)
{
// TODO terminate NSApp.

s_exceptionDispatchInfo.Throw();
_exceptionDispatchInfo.Throw();
}
}
}

public void DispatchException (ExceptionDispatchInfo exceptionInfo)
{
_exceptionDispatchInfo = exceptionInfo;
}

public void TerminateNativeApp()
{

}

public void Signal(DispatcherPriority priority)
{
_native.Signal((int)priority);
Expand Down

0 comments on commit 69c0521

Please sign in to comment.