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
tessTesselate infinite loop #23
Comments
|
Ditto for debugging this one. The merging function has infinite loop, which looks a bit dangerous. Could you try this one instead (have not tested): int tessMeshMergeConvexFaces( TESSmesh *mesh, int maxVertsPerFace )
{
TESShalfEdge *e, *eNext, *eSym;
TESShalfEdge *eHead = &tess->mesh->eHead;
int curNv, symNv;
for( e = eHead->next; e != eHead; e = eNext )
{
eNext = e->next;
eSym = eCur->Sym;
if( !eSym )
continue;
// Both faces must be inside
if( !e->Lface || !e->Lface->inside )
continue;
if( !eSym->Lface || !eSym->Lface->inside )
continue;
curNv = CountFaceVerts( e->Lface );
symNv = CountFaceVerts( eSym->Lface );
if( (curNv+symNv-2) > maxVertsPerFace )
continue;
// Merge if the resulting poly is convex.
if( VertCCW( e->Lprev->Org, e->Org, eSym->Lnext->Lnext->Org ) &&
VertCCW( eSym->Lprev->Org, eSym->Org, e->Lnext->Lnext->Org ) )
{
if( e == eNext || e == eNext->Sym ) { eNext = eNext->next; }
if( !tessMeshDelete( mesh, e ) )
return 0;
}
}
return 1;
}The idea is to walk through all edges (instead of faces), and remove them. It has the same pointer checking as |
|
I modified it slight but that stops the infinite loop, thanks! I'll do some more testing later but appreciate getting back to me so fast! |
|
good! this version could be a bit more understandable: int tessMeshMergeConvexFaces( TESSmesh *mesh, int maxVertsPerFace )
{
TESShalfEdge *e, *eNext, *eSym;
TESShalfEdge *eHead = &tess->mesh->eHead;
int leftNv, rightNv;
TESSvertex *va, *vb, *vc, *vd, *ve, *vf;
for( e = eHead->next; e != eHead; e = eNext )
{
eNext = e->next;
// Both faces must be inside
if( !e->Lface || !e->Lface->inside )
continue;
if( !e->Rface || !e->Rface->inside )
continue;
leftNv = CountFaceVerts( e->Lface );
rightNv = CountFaceVerts( e->Rface );
if( (leftNv+leftNv-2) > maxVertsPerFace )
continue;
// Merge if the resulting poly is convex.
//
// vf--ve--vd
// ^|
// left e || right
// |v
// va--vb--vc
va = e->Lprev->Org;
vb = e->Org;
vc = e->Sym->Lnext->Dst;
vd = e->Sym->Lprev->Org;
ve = e->Sym->Org;
vf = e->Lnext->Dst;
if( VertCCW( va, vb, vc ) && VertCCW( vd, ve, vf ) )
{
if( e == eNext || e == eNext->Sym ) { eNext = eNext->next; }
if( !tessMeshDelete( mesh, e ) )
return 0;
}
}
return 1;
}be sure to check that you get other than triangles as output too :) if it works equally good, i would appreciate a PR :) now to change some diapers... |
|
This follow on one seems to cause a separate crash for some reason. The change I made to it was "&tess->mesh->eHead;" -> "&mesh->eHead;" |
|
Thanks for the repro. I finally go around adding for for this, sorry it took so long. |
* commit '56d5c87b596bfe792f79b2e41fde83b769f6406d': Fix for memononen#30 Spaces --> tabs Replace calcAngle() with inCircle() to avoid expensive trigonometry Spaces --> tabs Fix issues Add TESS_REVERSE_CONTOURS to TessOption Add a reversed flag to tessAddContour() Fix for memononen#14 Fix for memononen#23 Fix for memononen#22 Updated link to license Small tweaks to CDT # Conflicts: # Example/example.c # Source/sweep.c # Source/tess.c # Source/tess.h
* origin/original: Fix for memononen#30 Spaces --> tabs Replace calcAngle() with inCircle() to avoid expensive trigonometry Spaces --> tabs Fix issues Add TESS_REVERSE_CONTOURS to TessOption Add a reversed flag to tessAddContour() Fix for memononen#14 Fix for memononen#23 Fix for memononen#22 Updated link to license Small tweaks to CDT # Conflicts: # Include/tesselator.h # Source/geom.c # Source/mesh.c # Source/sweep.c # Source/tess.c # Source/tess.h
Hi from Unity again! We're seeing the occasional "freeze" reported in libtess2 from the PolygonCollider2D. The following code consistently freezes it it 'tessMeshMergeConvexFaces'. Last report honest!
The text was updated successfully, but these errors were encountered: