Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge case causing triangulation error due to null reference exception #5

Open
catiejo opened this issue Apr 13, 2021 · 0 comments
Open

Comments

@catiejo
Copy link

catiejo commented Apr 13, 2021

Hello!

I've been using your code for my thesis project, and came across an edge case where triangulating the mesh for composite shape with holes fails. It happens when the very first hull point meets all the criteria to be the intersection for the hole's bridge point.

Code Error + Possible Fix

Here's the code that keeps failing (Triangulator.cs, line 161):

bool connectToThisDuplicateEdge = holeData.bridgePoint.y > potentialNewBridgeNode.Previous.Value.position.y;

When you are on the first run through the while (currentNode != null) loop, and potentialNewBridgeNode gets set to p0, there is no .Previous so it aborts with a null reference exception.

Based on my understanding of what's going on in the code, I changed it to this, and now everything seems to be working.

bool connectToThisDuplicateEdge = false;
if (potentialNewBridgeNode.Previous != null) {
      connectToThisDuplicateEdge = holeData.bridgePoint.y > potentialNewBridgeNode.Previous.Value.position.y;
}

Steps to Reproduce

The image below outlines a simple example that replicates the error. I want to create a composite shape that is rectangular, with a rectangular hole cut out of it. I have the following points, shown as vertices on the left and plotted on the graph in the center. The blue points represent the first shape in my shapeList, and the orange/red represents the second shape. I call (new CompositeShape(shapeList)).getMesh(). The red point marks the bridge point that connects the hole to the rest of the hull. Finally, GenerateVertices() gets called with the Polygon object on the right.
reproduce-error

Hopefully this helps you figure out exactly what's going on. My fix seems to work fine for my use case, but I'm not 100% that it doesn't break under other circumstances.

Anyway, thanks for providing this code, along with a video tutorial! It's been super helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant