Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzart90 committed Feb 2, 2024
1 parent f15f891 commit 36dd65c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
36 changes: 26 additions & 10 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ protected DynamoViewModel(StartConfiguration startConfiguration)
this.model = startConfiguration.DynamoModel;
this.model.CommandStarting += OnModelCommandStarting;
this.model.CommandCompleted += OnModelCommandCompleted;
this.model.RequestsCrashPrompt += Controller_RequestsCrashPrompt;

this.HideReportOptions = startConfiguration.HideReportOptions;
UsageReportingManager.Instance.InitializeCore(this);
Expand Down Expand Up @@ -775,6 +776,18 @@ protected DynamoViewModel(StartConfiguration startConfiguration)
MLDataPipelineExtension = model.ExtensionManager.Extensions.OfType<DynamoMLDataPipelineExtension>().FirstOrDefault();
}

private void Controller_RequestsCrashPrompt(object sender, CrashPromptArgs args)
{
if (CrashReportTool.ShowCrashErrorReportWindow(this,
(args is CrashErrorReportArgs cerArgs) ? cerArgs :
new CrashErrorReportArgs(args.Details)))
{
return;
}
// Backup crash reporting dialog (in case ADSK CER is not found)
var prompt = new Nodes.Prompts.CrashPrompt(args, this);
prompt.ShowDialog();
}

private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
Expand Down Expand Up @@ -826,32 +839,33 @@ internal void CrashGracefully(Exception ex, bool fatal = false)
// Fatal exception. Close Dynamo and terminate the process.

// Run the Dynamo exit code in the UI thread since CrashGracefully could be called in other threads too.
UIDispatcher?.Invoke(() => {
TryDispatcherInvoke(() => {
try
{
Exit(false);
}
catch { }
}, DispatcherPriority.Send);
});

// We terminate the process here so that no other exceptions can leak to the host apps.
// All fatal exceptions will result in a process termination (either by Dynamo, host app or CLR)
Environment.Exit(1);
// Do not terminate the process in the plugin, because other AppDomain.UnhandledException events will not get a chance to get called
// ex. A host app (like Revit) could have an AppDomain.UnhandledException too.
// If we terminate the process here, the host app will not get a chance to gracefully shut down.
// Environment.Exit(1);
}
else
{
// Non fatal exception.

// We run the Dynamo exit call asyncronously in the dispatcher to ensure that any continuation of code
// manages to run to completion before we start shutting down Dynamo.
UIDispatcher?.BeginInvoke(() => {
TryDispatcherBeginInvoke(() => {
try
{
Exit(false);
}
catch
{ }
}, DispatcherPriority.Send);
});
}
}
catch
Expand Down Expand Up @@ -3568,14 +3582,18 @@ public bool PerformShutdownSequence(ShutdownParams shutdownParams)
// that the shutdown may not be stopped.
shutdownSequenceInitiated = true;

AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
Dispatcher.CurrentDispatcher.UnhandledException -= CurrentDispatcher_UnhandledException;
TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
this.Model.RequestsCrashPrompt -= Controller_RequestsCrashPrompt;

// Request the View layer to close its window (see
// ShutdownParams.CloseDynamoView member for details).
if (shutdownParams.CloseDynamoView)
{
OnRequestClose(this, EventArgs.Empty);
}


BackgroundPreviewViewModel.Dispose();
foreach (var wsvm in workspaces)
{
Expand All @@ -3586,8 +3604,6 @@ public bool PerformShutdownSequence(ShutdownParams shutdownParams)
model.ShutDown(shutdownParams.ShutdownHost);
UsageReportingManager.DestroyInstance();

Dispatcher.CurrentDispatcher.UnhandledException -= CurrentDispatcher_UnhandledException;
TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
this.model.CommandStarting -= OnModelCommandStarting;
this.model.CommandCompleted -= OnModelCommandCompleted;
BackgroundPreviewViewModel.PropertyChanged -= Watch3DViewModelPropertyChanged;
Expand Down
15 changes: 0 additions & 15 deletions src/DynamoCoreWpf/Views/Core/DynamoView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ internal PreferencesView PreferencesWindow {
/// <param name="dynamoViewModel">Dynamo view model</param>
public DynamoView(DynamoViewModel dynamoViewModel)
{
dynamoViewModel.Model.RequestsCrashPrompt += Controller_RequestsCrashPrompt;
// The user's choice to enable hardware acceleration is now saved in
// the Dynamo preferences. It is set to true by default.
// When the view is constructed, we enable or disable hardware acceleration based on that preference.
Expand Down Expand Up @@ -1606,19 +1605,6 @@ private void Selection_CollectionChanged(object sender, NotifyCollectionChangedE
dynamoViewModel.NodeFromSelectionCommand.RaiseCanExecuteChanged();
}

private void Controller_RequestsCrashPrompt(object sender, CrashPromptArgs args)
{
if (CrashReportTool.ShowCrashErrorReportWindow(dynamoViewModel,
(args is CrashErrorReportArgs cerArgs) ? cerArgs :
new CrashErrorReportArgs(args.Details)))
{
return;
}
// Backup crash reporting dialog (in case ADSK CER is not found)
var prompt = new CrashPrompt(args, dynamoViewModel);
prompt.ShowDialog();
}

private void Controller_RequestTaskDialog(object sender, TaskDialogEventArgs e)
{
var taskDialog = new UI.Prompts.GenericTaskDialog(e);
Expand Down Expand Up @@ -1982,7 +1968,6 @@ private void WindowClosed(object sender, EventArgs e)

if (dynamoViewModel.Model != null)
{
dynamoViewModel.Model.RequestsCrashPrompt -= Controller_RequestsCrashPrompt;
dynamoViewModel.Model.RequestTaskDialog -= Controller_RequestTaskDialog;
dynamoViewModel.Model.ClipBoard.CollectionChanged -= ClipBoard_CollectionChanged;
}
Expand Down

0 comments on commit 36dd65c

Please sign in to comment.