This one isn’t initially fatal, but the same code works fine under v5. Curious what might have changed
System.AccessViolationException occurred
HResult=-2147467261
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=RhinoCommon
StackTrace:
at UnsafeNativeMethods.ONX_ModelComponentIterator_GetNext(IntPtr modelIterator, Int32& outIndex, ModelComponentType& outType, Guid& outId)
at Rhino.FileIO.File3dmManifestTable.<GetEnumerator>d__11.MoveNext()
at Rhino.FileIO.ManifestTable.<GetEnumerator>d__23`1.MoveNext()
at SMT.SuperWorkCell.ImportWCObjects(Dictionary`2 objDicts, String importPath) in
InnerException:
Here’s the code, exception occurs on the inner loop. If I ignore, it will usually get through it…Of course then my program doesn’t work, as its missing the hundreds of things I needed to import. I also tried opening and saving the targeted file in V6(with new name of course ). No luck. Also, and maybe its too early to say this. But my V6 is running much slower than the V5…but it could be this method causing all the headache.
Index access is used only for indexed components (like layers). Model geometry components are not indexed and that’s why the manifest table for geometry components appears empty. The fact that you could access geometry components by index was a bug, which has been fixed for the next Rhino WIP.
Here is the proper workflow:
using (var file = File3dm.Read(filename))
{
RhinoApp.WriteLine($"Object count = {file.Objects.Count}");
var obj_count = 0;
foreach (var obj in file.Objects)
{
if (null != obj)
obj_count++;
}
RhinoApp.WriteLine($"Objects accessed by enumerating = {obj_count}");
}