RhinoMeshUnwrapper crashes

Hello !

I develop several Rhino plugins for rendering and I would like to automatically unwrap render meshes that doesn’t have UV mapping set by the user.

For that purpose, I recklessly used:
RhinoMeshUnwrapper rhUnwrapper(onMesh); rhUnwrapper.Unwrap(RhinoMeshUnwrapper::UnwrapMethod::LSCM);

But Rhino 8 SDK crashes because of a read access violation while running unwrap method. I probably do something wrong, either with the mesh, or with the unwrapper, however I don’t know what and the method is supposed to return false instead of segfault.

I would also like to point out that the same error is raised by C# SDK.

Could someone explain me how to code it properly, and potentially fix this please ?

Error message :
Exception thrown: read access violation.
pNVI was 0x2B928006288.

Broken_tire.3dm (940.0 KB)

Probably something @Jussi_Aaltonen might want to have a look at.

1 Like

Hi @Guillaume_Chereau

This sounds like something already reported once: MeshUnwrapper object freeze bug

Please, could you try your code after deleting the double precision vertices from the mesh object?

You can delete them with the hidden _TestDestroyDoublePrecisionVertices command.

Thank you for your quick answer, but unfortunately that doesn’t seem to be enough to fix the bug.

As you can see, I just tried to replace double by simple precision vertices and remove the double ones, but it didn’t make any difference.

Here is a screenshot of the debugger, I invite you to pay attention to the callstack, where is mentioned the line where code crashes.

Regards !

Thanks for checking that. I had a closer look at your model and how it unwraps.

Regarding the crash, I have updated RH-69383. This is getting fixed.

Regarding poor documentation, here’s how RhinoMeshUnwrapper should be used. Every mesh edge that you want to keep connected needs to be welded (connected faces reference the same vertex at both ends of the edge).
So if you want to unwrap a box into a cross shape. You need to weld all the edges you want to keep connected and unweld the edges you want as seams.

Here’s the unwelded edges
CubeSeams
Here’s the result

And here’s the test command I used for testing.

class CTestUnwrapMeshCmd : public CRhinoTestCommand
{
public:
  CTestUnwrapMeshCmd() {}
  ~CTestUnwrapMeshCmd() {}
  UUID CommandUUID()
  {
    // {E36DF8C4-560A-4850-A8BD-09BF4F951D05}
    static const GUID uuid =
    { 0xe36df8c4, 0x560a, 0x4850, { 0xa8, 0xbd, 0x9, 0xbf, 0x4f, 0x95, 0x1d, 0x5 } };
    return uuid;
  }
  const wchar_t* EnglishCommandName() { return RHINOSTRING_COMMAND_NAME(L"TestUnwrapMesh"); }
  CRhinoCommand::result RunCommand(const CRhinoCommandContext& cc)
  {
    CRhinoDoc* pDoc = cc.Document();
    if (nullptr == pDoc)
      return CRhinoCommand::failure;
    CRhinoGetObject go;
    go.SetGeometryFilter(ON::mesh_object);
    go.SetCommandPrompt(L"Select a mesh to unwrap");
    go.GetObjects(1, 1);
    if (CRhinoCommand::success != go.CommandResult())
      return go.CommandResult();
    const CRhinoMeshObject* mesh_object =
      CRhinoMeshObject::Cast(go.Object(0).Object());
    if (0 == mesh_object)
      return CRhinoCommand::failure;
    const ON_Mesh* mesh = mesh_object->Mesh();
    if (0 == mesh)
      return CRhinoCommand::failure;
    ON_Mesh unwrappedMesh(*mesh);
    RhinoMeshUnwrapper unwrapper(unwrappedMesh);
    if (unwrapper.Unwrap(RhinoMeshUnwrapper::UnwrapMethod::LSCM) && unwrappedMesh.HasTextureCoordinates())
    {
      for (int vi = 0; vi < unwrappedMesh.VertexCount(); vi++)
      {
        const ON_2fPoint tc = unwrappedMesh.m_T[vi];
        unwrappedMesh.SetVertex(vi, ON_3dPoint(tc.x, tc.y, 0.0));
      }
      unwrappedMesh.UpdateDoublePrecisionVertices();
      unwrappedMesh.ComputeFaceNormals();
      unwrappedMesh.ComputeVertexNormals();
      ON_3dmObjectAttributes attrs(mesh_object->Attributes());
      attrs.SetName(L"Unwrapped Mesh", true);
      unwrappedMesh.IsValid();
      pDoc->AddMeshObject(unwrappedMesh, &attrs);
    }
    return CRhinoCommand::success;
  }
};
CTestUnwrapMeshCmd theTestUnwrapMeshCommand;

I will improve the SDK documentation for this as well: RH-94400 MeshUnwrapper documenatation

RH-69383 is fixed in Rhino 8 Service Release 31 Release Candidate