Repository navigation
LBIE: keep the hexa vertex walk on the grid (intermittent hexahedralize crash) - #677
Merged
Merged
Conversation
…ze crash) Octree::get_vtx_new() moves each hexa vertex onto the isosurface by walking across the finest cells. Where the surface meets the volume's boundary the walk stepped off the grid: a vertex on the far face gives a cell index of 2^oct_depth, and stepping past the edge goes to -1 or 2^oct_depth. xyz2octcell() returns -1 for those, and getCellValues(-1) read orig_vol out of bounds. Release builds crashed about 1 run in 15 on the CLI tests' tetrahedron SDF (Regression_MeshImproveMethodsNoCrash, HexahedralizeMethodAndImproveFlags), with or without --improve, and AddressSanitizer reports the read on every run. The vertex also landed outside the volume. The walk now starts in the nearest real cell and stops on the last cell's boundary when the next cell would be outside the grid. LbieMesherTest.HexaVerticesStayInsideAVolumeTheSurfaceLeaves meshes two spheres larger than their box and checks every vertex stays inside it; it fails without the fix (44 and 1 coordinates outside).
This was referenced Oct 18, 2026
transfix
added a commit
that referenced
this pull request
Oct 24, 2026
… reused vertex 0 (#777) `cvc hexahedralize --improve optimization` exited 0 but wrote garbage vertices. The cause is an uninitialized read in Octree::optimization, fed by degenerate hexahedra that geoframe::AddVert's refine_edge initialization produced. Refinement. AddVert gives each vertex 18 refine_edge slots, free when -1, but initialized them with `int_18 neg1_18 = { { -1 } }`, which sets only slot 0 and zeroes the rest. Once one edge or face was refined at a vertex, AddRefine_edgevtx_hex and AddRefine_facevtx (and AddRefine_edgevtx, for QUAD) found no free slot and returned vertex 0 instead of a new vertex. In the bunny's adaptive hex mesh (`cvc sdf -d 16,16,16 -a v2`) 338 of 351 hexahedra had vertex 0 in place of a corner; 1731 corners had a NaN condition number and 302 an infinite one. All 18 slots now start at -1: the mesh has 592 vertices instead of 200, no hexahedron repeats a vertex, and every corner is finite (worst condition number 169). Optimization. Octree::optimization moves the vertex of the worst corner down the gradient until that corner is no worse than cond_max. A flat corner (Jacobian 0) has condition +inf, so cond_max + 1.0f - cond_max is NaN (or 0 once cond_max >= 2^24), the line search never ran, and its result mmv4 went into the mesh uninitialized. What came out depended on the stack: (-2.6e13, 0.03, -1.9e13) from an October RelWithDebInfo build, (1.2501, 0, 0) from a current Release cvc.exe, (7.4e24, 5.8e-43, 7.9e24) in a test binary, then NaN once the next pass used them. mmv4 now starts at the corner itself, the step halving ends at 0 (it looped forever when no step qualified), and a non-finite position is never written. The same routine moved the wrong vertex for corners 4..7: it read quads[6h+1][j-4], which is v5, v4, v7, v6 for j = 4..7, and corner 4's line search used corner 1's edges. Its per-vertex statistics read quads[6h][4] for j == 4, past the end of the quad. A table of each corner's quad and slot replaces both. The intermittent access violation the CLI tests hit (Regression_MeshImproveMethodsNoCrash, HexahedralizeMethodAndImproveFlags) is not here: it was the hexa vertex walk fixed by #677. On a pre-#677 build, both crashes in 400 runs of the bunny command stopped after "finished traverse qef", before optimization runs. Current master crashes 0 times in 2000. Tests (lbie_mesher_test, cvc_cli_test), each failing against master's cvc.dll / cvc.exe or header and passing here: - RefinementMakesAVertexPerEdgeAndFace: a second edge and a face refined at one vertex get new vertices (master returns 0 for both). - AdaptiveHexahedraHaveEightDistinctCorners: a 17^3 sphere of radius 1.2 (master: 702 of 729 hexahedra repeat a vertex). - OptimizationLeavesAFlatCornerInPlace: one hexahedron with a flat corner comes back unchanged (master wrote (2.2e22, 0, 2.4e22) into vertex 0, then NaN). - OptimizationMovesTheWorstCornersOwnVertex: with corner 6 worst, v6 moves and v7 does not (master wrote v6's new position onto v7). - Regression_HexahedralizeOptimizationKeepsVerticesInTheVolume: every vertex the CLI writes lies in the volume (master: 11 of 334 outside).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CvcCliTest.Regression_MeshImproveMethodsNoCrashandCvcCliTest.HexahedralizeMethodAndImproveFlagsfailed now and then with an access violation (0xC0000005) incvc hexahedralize.Reproduction. On the CLI tests' input (the tetrahedron SDF,
sdf -d 16,16,16 -a v2), the releasecvc hexahedralize -i sdf.rawiv -o out.off -v 0.0crashed:--improve--improve edge-contract--improve geo-flowThe output always stopped after "finished traverse qef", so the crash is in hex mesh extraction, not in
--improve. WithOMP_NUM_THREADS=1it crashed 0 of 80 times. OpenMP wasn't racing, though: its threads only change the heap layout around a bad read.Cause (AddressSanitizer,
/fsanitize=address /Z7, flags it on every run): a 4-byte heap-buffer-overflow read.get_vtx_new()moves each hexa vertex onto the isosurface by walking across the finest cells. Where the surface meets the volume's boundary, the walk stepped off the grid in two ways:2^oct_depth;2^oct_depth.xyz2octcell()returns -1 for both, andgetCellValues(-1)readsorig_volout of bounds. The vertex also lands outside the volume.What
In
get_vtx_new():[0, 2^oct_depth));Vertex and element counts are unchanged on the inputs checked: 334 vertices for the CLI's SDF; 344 vertices / 4374 quads and 64 / 162 for the test spheres.
Tests
LbieMesherTest.HexaVerticesStayInsideAVolumeTheSurfaceLeavesmeshes spheres of radius 1.2 and 1.5 in a [-1, 1]³ box, so the surface leaves the box, and checks every vertex stays inside it. Without the fix it fails deterministically, with no sanitizer needed: 44 and 1 coordinates outside, the same on every run. With the fix it passes.cvc hexahedralize: 0 crashes in 80 runs without--improveand 0 in 80 with--improve edge-contract(before, about 1 in 15).hexahedralize -m libisocontourand-m fastcontouring;Regression_MeshImproveMethodsNoCrash,Regression_LayerMeshImproveMethodsNoCrash,HexahedralizeMethodAndImproveFlags) passed 10 of 10--gtest_repeatruns.lbie_mesher_testpasses 37/37.StateClusterMembership.FailureDetectionDead, a heartbeat-timing flake under-j 8.Found, not fixed (latent; ASan did not hit them on these inputs)
is_min_vertexaccepts corners outside the volume. It setsvtx[i] = -1in anunsigned intarray and then checksvtx[i] >= 0, which is always true, so a corner wheremin_vtx_hexareturned -1 would be accepted as vertex 4294967295.min_vtx_hexacan step to a negative level. It loopswhile (level == 0 || !is_refined(…, level - 1)). At level 0 that steps to level -1 and callsis_refined(…, -2), which indexeslevel_id[-2]. It is only reachable when the octree's root is a leaf.LBIE_geoframe.h:AddVertinitializesrefine_edgewithint_18 neg1_18 = { { -1 } }, which sets only element 0 to -1 and the other 17 to 0;AddBound_edgedoesn't stop after filling an empty slot, so it copies the edge into every remaining slot.