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

Properly handle empty CSGShapes #44718

Merged
merged 1 commit into from
Dec 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions modules/csg/csg_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ CSGPrimitive3D::CSGPrimitive3D() {

CSGBrush *CSGMesh3D::_build_brush() {
if (!mesh.is_valid()) {
return nullptr;
return memnew(CSGBrush);
}

Vector<Vector3> vertices;
Expand All @@ -718,7 +718,7 @@ CSGBrush *CSGMesh3D::_build_brush() {

if (arrays.size() == 0) {
_make_dirty();
ERR_FAIL_COND_V(arrays.size() == 0, nullptr);
ERR_FAIL_COND_V(arrays.size() == 0, memnew(CSGBrush));
}

Vector<Vector3> avertices = arrays[Mesh::ARRAY_VERTEX];
Expand Down Expand Up @@ -839,7 +839,7 @@ CSGBrush *CSGMesh3D::_build_brush() {
}

if (vertices.size() == 0) {
return nullptr;
return memnew(CSGBrush);
}

return _create_brush_from_arrays(vertices, uvs, smooth, materials);
Expand Down Expand Up @@ -1501,7 +1501,7 @@ CSGBrush *CSGTorus3D::_build_brush() {
float max_radius = outer_radius;

if (min_radius == max_radius) {
return nullptr; //sorry, can't
return memnew(CSGBrush); //sorry, can't
}

if (min_radius > max_radius) {
Expand Down Expand Up @@ -1720,7 +1720,7 @@ CSGBrush *CSGPolygon3D::_build_brush() {
// set our bounding box

if (polygon.size() < 3) {
return nullptr;
return memnew(CSGBrush);
}

Vector<Point2> final_polygon = polygon;
Expand All @@ -1732,7 +1732,7 @@ CSGBrush *CSGPolygon3D::_build_brush() {
Vector<int> triangles = Geometry2D::triangulate_polygon(final_polygon);

if (triangles.size() < 3) {
return nullptr;
return memnew(CSGBrush);
}

Path3D *path = nullptr;
Expand Down Expand Up @@ -1766,15 +1766,15 @@ CSGBrush *CSGPolygon3D::_build_brush() {

if (mode == MODE_PATH) {
if (!has_node(path_node)) {
return nullptr;
return memnew(CSGBrush);
}
Node *n = get_node(path_node);
if (!n) {
return nullptr;
return memnew(CSGBrush);
}
path = Object::cast_to<Path3D>(n);
if (!path) {
return nullptr;
return memnew(CSGBrush);
}

if (path != path_cache) {
Expand All @@ -1792,10 +1792,10 @@ CSGBrush *CSGPolygon3D::_build_brush() {
}
curve = path->get_curve();
if (curve.is_null()) {
return nullptr;
return memnew(CSGBrush);
}
if (curve->get_baked_length() <= 0) {
return nullptr;
return memnew(CSGBrush);
}
}
CSGBrush *brush = memnew(CSGBrush);
Expand Down