Thank you for the suggestions gang! I spent the day troubleshooting without any success. Here’s were things get a bit odd… On further inspection, I can process the previously attached SLDPRT fine by it’s own, it’s only when looping over that part and another part(s) does the crash seem to happen.
@menno - I integrated the UnhandledException Event example into my console app, but it doesn’t seem to work for this exception.
What I’m doing with my console application is looping over *.SLDPRT files and saving them out as .3dm files. Using a single RhinoDoc in the session to do this. At the end of each part, I clear all RhinoDoc objects with -
foreach (var obj in doc.Objects)
doc.Objects.Purge(obj.RuntimeSerialNumber);
Below is the full.cs if anyone has any other ideas on how to handle this? Attached is also the .cs document as well as two test .SLDPRT files. Just place the two parts in the same folder, pass the folder path of the two parts as the argument into the app.
I could be very wrong, but it’s almost like the RhinoCore itself is throwing some sort of exception, not the console app. Thank you for following this! Just purchased a Rhino license, coming off an eval, and hoping there is a solution to this or I’m skunked!
Program.cs (2.6 KB)
SCREW;BH;HS;GB-70.2__M8-1.25 x 60.SLDPRT (3.5 MB)
SCREW;BH;HS;GB-70.2__M8-1.25 x 62.SLDPRT (3.6 MB)
using System;
using System.IO;
using Rhino.Runtime.InProcess;
using Rhino.Geometry;
using Rhino;
using System.Security.Permissions;
namespace Convert
{
class Program
{
#region Program static constructor
static Program()
{
RhinoInside.Resolver.Initialize();
}
#endregion
// Use STAThread for this app as we are starting Rhino in a mode that does actually
// include user interface (we just never show the main window). This allows for things
// like RhinoApp().RunScript to properly run.
[System.STAThread]
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
static void Main(string[] args)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
string rPath = args[0].Replace("/", "\\");
string[] filePaths = Directory.GetFiles(rPath, "*.SLDPRT");
try
{
using (new RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.Hidden ))
{
string dumpDir = "C:/Users/alpha/Documents/scratch/dev/dump";
var doc = RhinoDoc.Create("Small Objects - Meters");
foreach (string prt in filePaths)
{
Console.WriteLine(prt);
string filename = Path.GetFileNameWithoutExtension(prt);
string output3dm = Path.ChangeExtension(prt, ".3dm");
string importScript = string.Format("-_Import \"{0}\" _Enter -_Export Version=4 \"{1}\" _Enter", prt, output3dm);
bool r = RhinoApp.RunScript(importScript, false);
foreach (var obj in doc.Objects)
doc.Objects.Purge(obj.RuntimeSerialNumber);
}
RhinoApp.RunScript("-_Exit No", false);
}
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
Console.WriteLine("press any key to exit");
Console.ReadKey();
}
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
}
}
}
Here is the specific Exception for the above:
C:\Users\alpha\Documents\scratch\dev\scratch\error\SCREW;BH;HS;GB-70.2__M8-1.25 x 60.SLDPRT
C:\Users\alpha\Documents\scratch\dev\scratch\error\SCREW;BH;HS;GB-70.2__M8-1.25 x 62.SLDPRT
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at UnsafeNativeMethods.CRhinoApp_RunScript1(String script, Int32 echoMode)
at Convert.Program.Main(String[] args) in C:\Users\alpha\Documents\scratch\rhinoInside\rhino-developer-samples\rhino.inside\dotnet\SampleConvert\Program.cs:line 49
Press any key to continue . . .