CreatePatch function fails with closed polyline inputs

It seems an issue was introduced with the RhinoCommon Mesh.CreatePatch command recently. I am confident it used to work as expected as we have a long-running ShapeDiver plugin component based on the function which never caused issues. However, since one of the latest releases, the function appears to throw an error complaining that the input polyline is not closed, even though it is:

230615_CreatePatchIssue.gh (8.4 KB)

Not completely sure who to tag from the team here, I’ll give it a go with @dale and @wim :slight_smile:

Hi Mathieu -

Someone other than me will have to take a look at the code but it would help pin-pointing a change. I assume you are testing this on Rhino 7? I’ve opened the gh file in Rhino 7.25 from November 2022 and in Rhino 7.22 from September 2022 and am getting that same error in both of those.
I wouldn’t consider any of those to directly pre-date one of the latest release and am wondering if I should look at even older versions?
-wim

It does sound strange that it would be broken for so long already, but I guess it’s possible. We added the component to our plugin in May 2022 and I am quite sure it worked as expected then. I can test myself a service release from around that time but maybe you can point to me how to easily switch the service release I am using locally, this is something I did not figure out yet.

Hi Mathieu -
I’ve now tried 7.17 from April 2022 with the same result.

Especially on Windows, there is no easy way to do this: (a) previous releases are not available for public download, so you’d have to store those yourself; (b) on Windows, you have to uninstall the current version, and then install an earlier version.
On macOS - which is where I tested your file - it’s easier because there is no uninstalling involved. The dmg files are unpacked and as long as you name them differently, you can have multiple versions available to test.
I’ll PM you some links to different SRs.
-wim

Hi @mathieu1,

Mesh.CreatePatch thinks your polyline is not closed because the first and last point don’t match spot on - there is some floating point noise. Here is a cheap fix:

  private void RunScript(Polyline p, ref object A)
  {
    if (!p.IsClosed)
      p.Last = p.First;

    Mesh m = new Mesh();

    m = Mesh.CreatePatch(p, 0.1, null, null, null, null, false, 1);
    A = m;
  }

I’ve logged an issue so we can address this.

https://mcneel.myjetbrains.com/youtrack/issue/RH-75351

– Dale

Isn’t it better to close the polyline in this way?

 if (!p.IsClosed)
p.Add(p.First);

RH-75351 is fixed in Rhino 7 Service Release 32

1 Like