Curve.Offset and MSTest

I’m writing a set of grasshopper components in Visual Studio 2017, and I have a collection of unit tests (set up with Tom Makin’s solution here) that have been working well.

Any time I try to run tests that involve Curve.Offset(), though, it throws my favorite error: “Object reference not set to an instance of an object.” I spent some time yesterday debugging the problem and am pretty sure it’s this specific method, and all of its versions.

For reference, I’m testing a slightly reformatted version of this older grasshopper component (which uses Curve.Offset() just fine). Lines 50 & 51 are the troublemakers in the new project’s tests.

This is my first time unit testing, and some searching brought up references to threading, which I’m not completely proficient in. Is this issue a limitation of certain RhinoCommon methods, or is it something I’m just approaching the wrong way?

Error was thrown when Curve.Offset()[0] was called (or similar selection). But Curve.Offset returns null, explained below.

Maybe this has something to do with it/is what I should keep tabs on?

@dale has been looking at the curve offset function lately. Dale can you repeat this? My guess is that there is no active RhinoDoc when Rhino is run under this testing framework scenario, but that is just a guess as I haven’t tried it yet.

Right, somewhere in Tom’s notes it mentions his framework runs Rhino WIP in headless mode, and that RhinoDoc.ActiveDoc would be null.

That is correct. The offset curve function needs some revamping and we noticed recently that it used the active document to get tolerance values to used for calculations. With no doc, the function should simply fail and not throw some strange exception. That is what I’m hoping to better understand.

Hi @Chuck_Driesler,

Calling Curve.Offset on compute just returns null and without any exceptions, as I’d expect.

– Dale

Got it, thank you for taking the time to confirm/clarify. Am in uncharted territory but if I figure anything out I’ll share here.

Is there a space that I can watch for updates when Curve.Offset might be available, or similar? Not urgent/important, just still learning what resources are available.

Hi @Chuck_Driesler,

I believe you already have this link.

The ‘fix’ is slated for Rhino 7.

– Dale

1 Like

Here is a minimal reproduction of the issue using my test project. I get null back from Curve.Offset() as expected.

It’s on branch issues/offset

1 Like

I was just able to reproduce the null output also.

The error was being thrown because I called Curve.Offset()[0] (or similar) in an attempt to just get the individual curve. Which doesn’t make sense to do, now that I know all I’ll get is null. Thanks again for the details.