Skip to content

Commit 023bb59

Browse files
authored
Fix crashing on an empty MeshGL with one runIndex element (#1261)
1 parent 2984626 commit 023bb59

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/impl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ struct Manifold::Impl {
163163
runIndex = {0, static_cast<I>(runEnd)};
164164
} else if (runIndex.size() == meshGL.runOriginalID.size()) {
165165
runIndex.push_back(runEnd);
166+
} else if (runIndex.size() == 1) {
167+
runIndex.push_back(runEnd);
166168
}
167169

168170
const auto startID = Impl::ReserveIDs(meshGL.runOriginalID.size());

test/manifold_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ TEST(Manifold, ValidInput) {
103103
EXPECT_EQ(tet.Status(), Manifold::Error::NoError);
104104
}
105105

106+
TEST(Manifold, ValidInputOneRunIndex) {
107+
MeshGL emptyMesh;
108+
emptyMesh.runIndex = {0};
109+
Manifold empty(emptyMesh);
110+
EXPECT_TRUE(empty.IsEmpty());
111+
EXPECT_EQ(empty.Status(), Manifold::Error::NoError);
112+
}
113+
106114
TEST(Manifold, InvalidInput1) {
107115
MeshGL in = TetGL();
108116
in.vertProperties[2 * 3 + 1] = NAN;
@@ -155,6 +163,14 @@ TEST(Manifold, InvalidInput6) {
155163
EXPECT_EQ(tet.Status(), Manifold::Error::VertexOutOfBounds);
156164
}
157165

166+
TEST(Manifold, InvalidInput7) {
167+
MeshGL cube = CubeUV();
168+
cube.runIndex = {0, 1, static_cast<uint32_t>(cube.triVerts.size())};
169+
Manifold tet(cube);
170+
EXPECT_TRUE(tet.IsEmpty());
171+
EXPECT_EQ(tet.Status(), Manifold::Error::RunIndexWrongLength);
172+
}
173+
158174
TEST(Manifold, OppositeFace) {
159175
MeshGL gl;
160176
gl.vertProperties = {

0 commit comments

Comments
 (0)