ToList() on ObjectTable results in Nulls for Objects on Reference Layers

Hi,

As of Rhino 8.5 If i call ToList() on the ObjectTable i am seeing as many nulls as i have objects on reference layers. Example script below:

using System;
using Rhino;
using System.Linq;
using Rhino.Geometry;
using Rhino.DocObjects;

var doc = RhinoDoc.ActiveDoc;

// create reference layer
int layerId = doc.Layers.AddReferenceLayer(new Layer {	Name = "Ref"}); 
// add object 
var circle = new Circle(50).ToNurbsCurve();
doc.Objects.Add(circle,new ObjectAttributes {LayerIndex = layerId});

// BUG? this list now contains a null? 
var obs = doc.Objects.ToList();
Console.WriteLine("NULLS ="+obs.Count(o => o == null));
// yet this does not 
Console.WriteLine("NO nulls="+doc.Objects.Count(o => o == null));

foreach (var item in doc.Objects) {
  //  nor does this fire ?!?
   if (item == null) Console.WriteLine("Null found");
}

Has this always been the behaviour? Is it intended? or is it a regression?

System info attached, no plugins are loaded. systeminfo.txt (2.3 KB)

Hi @david.birch.uk,

Do I need a special .3dm file to repeat this, or does this happen with any file?

– Dale

@dale use the attached grasshopper script in a new document. Just opening it will add a layer and circle on that layer. Except on that very first run doc.Objects.ToList() gives a list with just one null entry instead of the actual object.

obj_tolist_checker.gh (7.6 KB)

Thanks @nathanletwory yeah the grasshopper script replicates the issue.
@dale this occurs on any file.

Logged as RH-81204 First added object is null after ToList

1 Like

Hi @david.birch.uk;

In this case:

var obs = doc.Objects.ToList();

.ToList returns an empty list. (same as new List<T>() );. This is standard LINQ behavior.

The default ObjectTable enumerator only searches for active objects - object are in the document. In your case, you are adding fake reference objects. So when the ObjectTable is enumerated, nothing is returned, thus the empty list.

In your case, use ObjectTable.GetObjectList and pass a custom ObjectEnumeratorSettings object.

Hope this helps,

– Dale

Thanks @dale

Sorry I think I am missing something here - indeed the empty list is the expected outcome.

However this is not what we are seeing - both @nathanletwory and I can see null’s being returned and not an empty list.

Where do the null values come from??

As far as i know they do not appear before 8.5

Hi @david.birch.uk,

Rhino 8.4 produces the same results.

– Dale