diff --git a/src/DynamoCore/Models/DynamoModel.cs b/src/DynamoCore/Models/DynamoModel.cs
index 50efa49d4aa..159e1111a77 100644
--- a/src/DynamoCore/Models/DynamoModel.cs
+++ b/src/DynamoCore/Models/DynamoModel.cs
@@ -2109,6 +2109,27 @@ private void DisplayInvalidInputSymbolWarning()
OnRequestTaskDialog(null, args);
}
+ internal event VoidHandler Preview3DOutage;
+ private void OnPreview3DOutage()
+ {
+ if (Preview3DOutage != null)
+ {
+ Preview3DOutage();
+ }
+ }
+
+ internal void Report3DPreviewOutage(string summary, string description)
+ {
+ OnPreview3DOutage();
+
+ const string imageUri = "/DynamoCoreWpf;component/UI/Images/task_dialog_future_file.png";
+ var args = new TaskDialogEventArgs(
+ new Uri(imageUri, UriKind.Relative),
+ Resources.Preview3DOutageTitle, summary, description);
+
+ OnRequestTaskDialog(null, args);
+ }
+
///
/// Remove a workspace from the dynamo model.
///
diff --git a/src/DynamoCore/Models/DynamoModelEvents.cs b/src/DynamoCore/Models/DynamoModelEvents.cs
index 2a381d3cbe9..f65cd0c6a5f 100644
--- a/src/DynamoCore/Models/DynamoModelEvents.cs
+++ b/src/DynamoCore/Models/DynamoModelEvents.cs
@@ -283,7 +283,7 @@ public void OnRequestsCrashPrompt(object sender, CrashPromptArgs args)
internal delegate void TaskDialogHandler(object sender, TaskDialogEventArgs e);
internal event TaskDialogHandler RequestTaskDialog;
- internal void OnRequestTaskDialog(object sender, TaskDialogEventArgs args)
+ internal virtual void OnRequestTaskDialog(object sender, TaskDialogEventArgs args)
{
if (RequestTaskDialog != null)
RequestTaskDialog(sender, args);
diff --git a/src/DynamoCore/Properties/Resources.Designer.cs b/src/DynamoCore/Properties/Resources.Designer.cs
index 3c31307df9b..fe5af09064b 100644
--- a/src/DynamoCore/Properties/Resources.Designer.cs
+++ b/src/DynamoCore/Properties/Resources.Designer.cs
@@ -1162,6 +1162,15 @@ public static string PortsNameDescriptionDoNotEqualWarningMessage {
}
}
+ ///
+ /// Looks up a localized string similar to 3D preview has been deactivated.
+ ///
+ public static string Preview3DOutageTitle {
+ get {
+ return ResourceManager.GetString("Preview3DOutageTitle", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Proceed anyway.
///
diff --git a/src/DynamoCore/Properties/Resources.en-US.resx b/src/DynamoCore/Properties/Resources.en-US.resx
index bf707718a4e..a251ef48feb 100644
--- a/src/DynamoCore/Properties/Resources.en-US.resx
+++ b/src/DynamoCore/Properties/Resources.en-US.resx
@@ -709,4 +709,7 @@ Restart Dynamo to complete the uninstall.
Attempting to load customNode {0} loaded by package {1}, but a previous definition named {2} exists with no associated package. The new customNode definition has been loaded, but Dynamo may be in an unstable state, please avoid loading multiple custom nodes with the id.
+
+ 3D preview has been deactivated
+
\ No newline at end of file
diff --git a/src/DynamoCore/Properties/Resources.resx b/src/DynamoCore/Properties/Resources.resx
index 10c1e95bc9d..88efd0b39c9 100644
--- a/src/DynamoCore/Properties/Resources.resx
+++ b/src/DynamoCore/Properties/Resources.resx
@@ -709,4 +709,7 @@ Restart Dynamo to complete the uninstall.
Attempting to load customNode {0} loaded by package {1}, but a previous definition named {2} exists with no associated package. The new customNode definition has been loaded, but Dynamo may be in an unstable state, please avoid loading multiple custom nodes with the id.
+
+ 3D preview has been deactivated
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/Properties/AssemblyInfo.cs b/src/DynamoCoreWpf/Properties/AssemblyInfo.cs
index f2fa7c99232..64da742f531 100644
--- a/src/DynamoCoreWpf/Properties/AssemblyInfo.cs
+++ b/src/DynamoCoreWpf/Properties/AssemblyInfo.cs
@@ -40,3 +40,4 @@
[assembly: InternalsVisibleTo("WorkspaceDependencyViewExtension")]
[assembly: InternalsVisibleTo("DocumentationBrowserViewExtension")]
[assembly: InternalsVisibleTo("SystemTestServices")]
+[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
diff --git a/src/DynamoCoreWpf/Properties/Resources.Designer.cs b/src/DynamoCoreWpf/Properties/Resources.Designer.cs
index 4b2a477ed1e..7d347886554 100644
--- a/src/DynamoCoreWpf/Properties/Resources.Designer.cs
+++ b/src/DynamoCoreWpf/Properties/Resources.Designer.cs
@@ -4652,6 +4652,24 @@ public static string QueryMember {
}
}
+ ///
+ /// Looks up a localized string similar to Please check if you intended to render this amount of geometry, and consider turning off the preview of other nodes within your graph, lowering the amount of Geometry you wish to render, or turning down the render precision..
+ ///
+ public static string RenderingMemoryOutageDescription {
+ get {
+ return ResourceManager.GetString("RenderingMemoryOutageDescription", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Dynamo has run out of memory trying to render your geometry. The geometry preview has been disabled..
+ ///
+ public static string RenderingMemoryOutageSummary {
+ get {
+ return ResourceManager.GetString("RenderingMemoryOutageSummary", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Apply Changes.
///
diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx
index 79ea4fb7937..d75cb608a60 100644
--- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx
+++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx
@@ -2242,4 +2242,10 @@ Uninstall the following packages: {0}?
Original node name:
+
+ Please check if you intended to render this amount of geometry, and consider turning off the preview of other nodes within your graph, lowering the amount of Geometry you wish to render, or turning down the render precision.
+
+
+ Dynamo has run out of memory trying to render your geometry. The geometry preview has been disabled.
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx
index 6b3de229122..db64e30d894 100644
--- a/src/DynamoCoreWpf/Properties/Resources.resx
+++ b/src/DynamoCoreWpf/Properties/Resources.resx
@@ -2242,4 +2242,10 @@ Uninstall the following packages: {0}?
Original node name:
+
+ Please check if you intended to render this amount of geometry, and consider turning off the preview of other nodes within your graph, lowering the amount of Geometry you wish to render, or turning down the render precision.
+
+
+ Dynamo has run out of memory trying to render your geometry. The geometry preview has been disabled.
+
\ No newline at end of file
diff --git a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
index 69b9099ccec..aac83b78455 100644
--- a/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
@@ -724,12 +724,14 @@ private void SubscribeModelUiEvents()
{
model.RequestBugReport += ReportABug;
model.RequestDownloadDynamo += DownloadDynamo;
+ model.Preview3DOutage += Disable3DPreview;
}
private void UnsubscribeModelUiEvents()
{
model.RequestBugReport -= ReportABug;
model.RequestDownloadDynamo -= DownloadDynamo;
+ model.Preview3DOutage -= Disable3DPreview;
}
private void SubscribeModelCleaningUpEvent()
@@ -868,6 +870,14 @@ internal static void DownloadDynamo()
Process.Start(new ProcessStartInfo("explorer.exe", Configurations.DynamoDownloadLink));
}
+ private void Disable3DPreview()
+ {
+ foreach (var item in Watch3DViewModels)
+ {
+ item.Active = false;
+ }
+ }
+
internal bool CanReportABug(object parameter)
{
return true;
diff --git a/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs b/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs
index abd9acfbe65..7c0422d6fff 100644
--- a/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs
+++ b/src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs
@@ -21,7 +21,9 @@
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
+using Dynamo.Models;
using Dynamo.Selection;
+using Dynamo.UI.Prompts;
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Visualization;
@@ -859,7 +861,17 @@ public override void GenerateViewGeometryFromRenderPackagesAndRequestUpdate(Rend
var meshPackages = packages.Cast().Where(rp => rp.MeshVertexCount % 3 == 0);
RemoveGeometryForUpdatedPackages(meshPackages);
- AggregateRenderPackages(meshPackages);
+ try
+ {
+ AggregateRenderPackages(meshPackages);
+ }
+ catch (OutOfMemoryException)
+ {
+ // This can happen when the amount of packages to render is too large
+ string summary = Resources.RenderingMemoryOutageSummary;
+ var description = Resources.RenderingMemoryOutageDescription;
+ (dynamoModel as DynamoModel).Report3DPreviewOutage(summary, description);
+ }
#if DEBUG
renderTimer.Stop();
Debug.WriteLine(string.Format("RENDER: {0} ellapsed for compiling assets for rendering.", renderTimer.Elapsed));
@@ -1635,7 +1647,7 @@ private void ToggleTreeViewItemHighlighting(string path, bool isSelected)
/// attaches them to the visual scene.
///
/// An of .
- private void AggregateRenderPackages(IEnumerable packages)
+ internal virtual void AggregateRenderPackages(IEnumerable packages)
{
IEnumerable customNodeIdents = null;
if (InCustomNode())
diff --git a/src/VisualizationTests/HelixWatch3DViewModelTests.cs b/src/VisualizationTests/HelixWatch3DViewModelTests.cs
index 2ec98fa2836..df5ec9e4f26 100644
--- a/src/VisualizationTests/HelixWatch3DViewModelTests.cs
+++ b/src/VisualizationTests/HelixWatch3DViewModelTests.cs
@@ -86,28 +86,21 @@ protected override void StartDynamo(TestSessionConfiguration testConfig)
}
}
- Model = DynamoModel.Start(
- new DynamoModel.DefaultStartConfiguration()
- {
- StartInTestMode = true,
- PathResolver = pathResolver,
- GeometryFactoryPath = preloader.GeometryFactoryPath,
- UpdateManager = this.UpdateManager,
- ProcessMode = TaskProcessMode.Synchronous
- });
+ Model = CreateModel(new DynamoModel.DefaultStartConfiguration()
+ {
+ StartInTestMode = true,
+ PathResolver = pathResolver,
+ GeometryFactoryPath = preloader.GeometryFactoryPath,
+ UpdateManager = this.UpdateManager,
+ ProcessMode = TaskProcessMode.Synchronous
+ });
Model.EvaluationCompleted += Model_EvaluationCompleted;
- ViewModel = DynamoViewModel.Start(
- new DynamoViewModel.StartConfiguration()
- {
- DynamoModel = Model,
- Watch3DViewModel =
- HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(
- null,
- new Watch3DViewModelStartupParams(Model),
- Model.Logger)
- });
+ var vmConfig = CreateViewModelStartConfiguration();
+ vmConfig.DynamoModel = Model;
+
+ ViewModel = DynamoViewModel.Start(vmConfig);
//create the view
View = new DynamoView(ViewModel);
@@ -116,6 +109,29 @@ protected override void StartDynamo(TestSessionConfiguration testConfig)
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
}
+ ///
+ /// Derived test classes can override this method to provide a customized Dynamo model.
+ ///
+ protected virtual DynamoModel CreateModel(DynamoModel.IStartConfiguration configuration)
+ {
+ return DynamoModel.Start(configuration);
+ }
+
+ ///
+ /// Derived test classes can override this method to provide a customized view model configuration.
+ ///
+ protected virtual DynamoViewModel.StartConfiguration CreateViewModelStartConfiguration()
+ {
+ return new DynamoViewModel.StartConfiguration()
+ {
+ DynamoModel = Model,
+ Watch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel(
+ null,
+ new Watch3DViewModelStartupParams(Model),
+ Model.Logger)
+ };
+ }
+
private async void Model_EvaluationCompleted(object sender, EvaluationCompletedEventArgs e)
{
DispatcherUtil.DoEvents();
diff --git a/src/VisualizationTests/Preview3DMemoryOutageTest.cs b/src/VisualizationTests/Preview3DMemoryOutageTest.cs
new file mode 100644
index 00000000000..67225e14329
--- /dev/null
+++ b/src/VisualizationTests/Preview3DMemoryOutageTest.cs
@@ -0,0 +1,75 @@
+using Dynamo.Models;
+using Dynamo.ViewModels;
+using Dynamo.Wpf.Rendering;
+using Dynamo.Wpf.ViewModels.Watch3D;
+using DynamoCoreWpfTests.Utility;
+using HelixToolkit.Wpf.SharpDX;
+using Moq;
+using Moq.Protected;
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WpfVisualizationTests
+{
+ [TestFixture]
+ public class Preview3DMemoryOutageTest : VisualizationTest
+ {
+ private Mock modelMock;
+
+ ///
+ /// Creates a mock DynamoModel that does not show a task dialog but instead sets its call
+ /// as a verifiable call.
+ ///
+ /// Default DynamoModel configuration
+ /// Mock DynamoModel
+ protected override DynamoModel CreateModel(DynamoModel.IStartConfiguration configuration)
+ {
+ modelMock = new Mock(configuration)
+ {
+ CallBase = true
+ };
+ modelMock.Setup(m => m.OnRequestTaskDialog(It.IsAny