Fixed some possible issues and access non-initialized variable in Carve BOP interface.

Discovered when was investigating some crashes caused by Carve's triangulator.
This commit is contained in:
Sergey Sharybin
2012-01-27 08:17:53 +00:00
parent 82300fabb9
commit 3062798de3

View File

@@ -150,12 +150,19 @@ static MeshSet<3> *Carve_unionIntersectingMeshes(MeshSet<3> *poly,
MeshSet<3> *right = Carve_getIntersectedOperand(orig_meshes, precomputedAABB, otherAABB);
try {
MeshSet<3> *result = csg.compute(left, right, carve::csg::CSG::UNION, NULL, carve::csg::CSG::CLASSIFY_EDGE);
if(left->meshes.size()==0) {
delete left;
delete left;
delete right;
left = right;
}
else {
MeshSet<3> *result = csg.compute(left, right, carve::csg::CSG::UNION, NULL, carve::csg::CSG::CLASSIFY_EDGE);
left = result;
delete left;
delete right;
left = result;
}
}
catch(carve::exception e) {
std::cerr << "CSG failed, exception " << e.str() << std::endl;
@@ -492,7 +499,7 @@ BoolOpState BOP_performBooleanOperation(BoolOpType opType,
CSG_VertexIteratorDescriptor obBVertices)
{
carve::csg::CSG::OP op;
MeshSet<3> *left, *right, *output;
MeshSet<3> *left, *right, *output = NULL;
carve::csg::CSG csg;
carve::geom3d::Vector min, max;
carve::interpolate::FaceAttr<uint> oface_num;
@@ -517,6 +524,17 @@ BoolOpState BOP_performBooleanOperation(BoolOpType opType,
Carve_prepareOperands(&left, &right, oface_num);
if(left->meshes.size() == 0 || right->meshes.size()==0) {
// normally sohuldn't happen (zero-faces objects are handled by modifier itself), but
// unioning intersecting meshes which doesn't have consistent normals might lead to
// empty result which wouldn't work here
delete left;
delete right;
return BOP_ERROR;
}
min.x = max.x = left->vertex_storage[0].v.x;
min.y = max.y = left->vertex_storage[0].v.y;
min.z = max.z = left->vertex_storage[0].v.z;