Skip to content

Commit

Permalink
2.4.1 - Sandbox should not crash silently (#10021)
Browse files Browse the repository at this point in the history
* use invariant culture to parse inputs to converters - (#10006)

* use invariant culture to parse inputs -
we were passing the culture before but this was usually set to en-us EVEN in localized enviornments
unless something set it explicitly
wrap with try catch and return some default conversion

* Update src/DynamoCoreWpf/UI/Converters.cs

* Update src/DynamoCoreWpf/UI/Converters.cs

(cherry picked from commit 3dc4202)

* merge conflicts
  • Loading branch information
mjkkirschner authored Sep 30, 2019
1 parent da85ea0 commit 31e0672
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 22 deletions.
15 changes: 14 additions & 1 deletion src/DynamoApplications/StartupUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace Dynamo.Applications
{
public class StartupUtils
{
//TODO internal?
/// <summary>
/// Raised when loading of the ASM binaries fails. A failure message is passed as a parameter.
/// </summary>
public static event Action<string> ASMPreloadFailure;

internal class SandboxLookUp : DynamoLookUp
{
public override IEnumerable<string> GetDynamoInstallLocations()
Expand Down Expand Up @@ -178,7 +184,14 @@ public static DynamoModel MakeModel(bool CLImode)
{
var geometryFactoryPath = string.Empty;
var preloaderLocation = string.Empty;
PreloadShapeManager(ref geometryFactoryPath, ref preloaderLocation);
try
{
PreloadShapeManager(ref geometryFactoryPath, ref preloaderLocation);
}
catch(Exception e)
{
ASMPreloadFailure?.Invoke(e.Message);
}

var config = new DynamoModel.DefaultStartConfiguration()
{
Expand Down
33 changes: 29 additions & 4 deletions src/DynamoSandbox/DynamoCoreSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Dynamo.Models;
using Dynamo.ViewModels;
using Dynamo.Wpf.ViewModels.Watch3D;
using System.Linq;
using Dynamo.DynamoSandbox.Properties;

namespace DynamoSandbox
{
Expand All @@ -19,6 +21,7 @@ class DynamoCoreSetup
private DynamoViewModel viewModel = null;
private string commandFilePath;
private Stopwatch startupTimer = Stopwatch.StartNew();
private const string sandboxWikiPage = @"https://github.com/DynamoDS/Dynamo/wiki/How-to-Utilize-Dynamo-Builds";

[DllImport("msvcrt.dll")]
public static extern int _putenv(string env);
Expand All @@ -36,9 +39,8 @@ public void RunApplication(Application app)
try
{
DynamoModel.RequestMigrationStatusDialog += MigrationStatusDialogRequested;

var model = Dynamo.Applications.StartupUtils.MakeModel(false);

Dynamo.Applications.StartupUtils.ASMPreloadFailure += ASMPreloadFailureHandler;
viewModel = DynamoViewModel.Start(
new DynamoViewModel.StartConfiguration()
{
Expand All @@ -58,6 +60,7 @@ public void RunApplication(Application app)
app.Run(view);

DynamoModel.RequestMigrationStatusDialog -= MigrationStatusDialogRequested;
Dynamo.Applications.StartupUtils.ASMPreloadFailure -= ASMPreloadFailureHandler;

}

Expand Down Expand Up @@ -85,16 +88,38 @@ public void RunApplication(Application app)
// Give user a chance to save (but does not allow cancellation)
viewModel.Exit(allowCancel: false);
}
else
{
//show a message dialog box with the exception so the user
//can effectively report the issue.
var shortStackTrace = String.Join(Environment.NewLine,e.StackTrace.Split(Environment.NewLine.ToCharArray()).Take(10));

var result = MessageBox.Show($"{Resources.SandboxCrashMessage} {Environment.NewLine} {e.Message}" +
$" {Environment.NewLine} {e.InnerException?.Message} {Environment.NewLine} {shortStackTrace} {Environment.NewLine} " +
Environment.NewLine + string.Format(Resources.SandboxBuildsPageDialogMessage, sandboxWikiPage),

"DynamoSandbox",
MessageBoxButton.YesNo,MessageBoxImage.Error);

if(result == MessageBoxResult.Yes)
{
System.Diagnostics.Process.Start(sandboxWikiPage);
}
}
}
catch
{
catch {
}

Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
}

private void ASMPreloadFailureHandler(string failureMessage)
{
MessageBox.Show(failureMessage, "DynamoSandbox", MessageBoxButton.OK, MessageBoxImage.Warning);
}

void OnDynamoViewLoaded(object sender, RoutedEventArgs e)
{
CloseMigrationWindow();
Expand Down
26 changes: 22 additions & 4 deletions src/DynamoSandbox/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/DynamoSandbox/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="SandboxBuildsPageDialogMessage" xml:space="preserve">
<value>Goto the Dynamo builds wiki site({0}) for more information.</value>
<comment>message directing user to wiki page</comment>
</data>
<data name="SandboxCrashMessage" xml:space="preserve">
<value>Could not start DynamoSandbox, unhandled exception.</value>
</data>
<data name="SettingsMigrationDialogMessage" xml:space="preserve">
<value>Migrating Settings ...</value>
<comment>Settings migration dialog message prompt</comment>
Expand Down
7 changes: 7 additions & 0 deletions src/DynamoSandbox/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="SandboxBuildsPageDialogMessage" xml:space="preserve">
<value>Goto the Dynamo builds wiki site({0}) for more information.</value>
<comment>message directing user to wiki page</comment>
</data>
<data name="SandboxCrashMessage" xml:space="preserve">
<value>Could not start DynamoSandbox, unhandled exception.</value>
</data>
<data name="SettingsMigrationDialogMessage" xml:space="preserve">
<value>Migrating Settings ...</value>
<comment>Settings migration dialog message prompt</comment>
Expand Down
43 changes: 32 additions & 11 deletions src/Tools/DynamoShapeManager/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class Utilities
/// <summary>
/// The mask to filter ASM binary
/// </summary>
public static readonly string ASMFileMask = "ASMAHL*.dll";
public static readonly string ASMFileMask = "ASMAHL*A.dll";
#endregion


Expand Down Expand Up @@ -147,6 +147,7 @@ public static Version GetInstalledAsmVersion2(IEnumerable<Version> versions, ref
getASMInstallsFunc = getASMInstallsFunc ?? GetAsmInstallations;
var installations = getASMInstallsFunc(rootFolder);


// first find the exact match or the lowest matching within same major version
foreach (var version in versions)
{
Expand Down Expand Up @@ -286,11 +287,11 @@ public static void PreloadAsmFromPath(string preloaderLocation, string asmLocati

if (string.IsNullOrEmpty(preloaderLocationToLoad))
{
throw new ArgumentException("Invalid LibG preloader location for ASM at " + asmLocation);
throw new ArgumentException($"Invalid LibG preloader location {preloaderLocation} for ASM at {asmLocation}");
}
if (string.IsNullOrEmpty(asmLocation) || !Directory.Exists(asmLocation))
{
throw new ArgumentException("Invalid ASM location " + asmLocation);
throw new ArgumentException($"Invalid ASM location { asmLocation }");
}
var preloaderPath = Path.Combine(preloaderLocationToLoad, PreloaderAssembly);

Expand All @@ -308,10 +309,18 @@ public static void PreloadAsmFromPath(string preloaderLocation, string asmLocati
throw new MissingMethodException(
string.Format("Method '{0}' not found", PreloaderMethodName));
}

var methodParams = new object[] { asmLocation };
preloadMethod.Invoke(null, methodParams);

try
{
var methodParams = new object[] { asmLocation };
preloadMethod.Invoke(null, methodParams);
}
catch
{
//log for clients like CLI.
var message = $"Could not load geometry library binaries from : {asmLocation}";
Console.WriteLine(message);
throw new Exception(message);
}
Debug.WriteLine("Successfully loaded ASM binaries");
}

Expand Down Expand Up @@ -401,7 +410,7 @@ public static string GetGeometryFactoryPath2(string rootFolder, Version version)

//lookup libG with a fallback to older versions which share the major version number.
var libGFolder = Utilities.GetLibGPreloaderLocation(version, rootFolder);

if (!Directory.Exists(libGFolder))
{
// LibG_version folder must be valid.
Expand All @@ -418,8 +427,8 @@ public static string GetGeometryFactoryPath2(string rootFolder, Version version)

return assemblyPath;
}


private static IEnumerable GetAsmInstallations(string rootFolder)
{
var assemblyPath = Path.Combine(Path.Combine(rootFolder, "DynamoInstallDetective.dll"));
Expand All @@ -441,7 +450,19 @@ private static IEnumerable GetAsmInstallations(string rootFolder)


var methodParams = new object[] { ProductsWithASM, ASMFileMask };
return installationsMethod.Invoke(null, methodParams) as IEnumerable;
var installs = installationsMethod.Invoke(null, methodParams) as IEnumerable;

//filter install locations missing tbb and tbbmalloc.dll
return installs.Cast<KeyValuePair<string, Tuple<int, int, int, int>>>().Where(install =>
{
var files = Directory.EnumerateFiles(install.Key, "tbb*.dll").Select(x=>System.IO.Path.GetFileName(x));
if (files.Contains("tbb.dll") && files.Contains("tbbmalloc.dll"))
{
return true;
}
return false;

});
}
}
}
8 changes: 6 additions & 2 deletions test/DynamoCoreTests/libGPreloaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,13 @@ public void GetInstalledASMVersions2_FindsVersionedLibGFolders_WithRootFolderFal

//create some
var libG22440path = System.IO.Directory.CreateDirectory(Path.Combine(rootFolder, "LibG_224_4_0"));
File.WriteAllText(Path.Combine(libG22440path.FullName, "ASMAHL.dll"), "someText");
File.WriteAllText(Path.Combine(libG22440path.FullName, "ASMAHL224A.dll"), "someText");
File.WriteAllText(Path.Combine(libG22440path.FullName, "tbb.dll"), "someText");
File.WriteAllText(Path.Combine(libG22440path.FullName, "tbbmalloc.dll"), "someText");
var libG22401path = System.IO.Directory.CreateDirectory(Path.Combine(rootFolder, "LibG_224_0_1"));
File.WriteAllText(Path.Combine(libG22401path.FullName, "ASMAHL.dll"), "someText");
File.WriteAllText(Path.Combine(libG22401path.FullName, "ASMAHL224A.dll"), "someText");
File.WriteAllText(Path.Combine(libG22401path.FullName, "tbb.dll"), "someText");
File.WriteAllText(Path.Combine(libG22401path.FullName, "tbbmalloc.dll"), "someText");


var foundVersion = DynamoShapeManager.Utilities.GetInstalledAsmVersion2(
Expand Down

0 comments on commit 31e0672

Please sign in to comment.