Skip to content

Commit

Permalink
Merge pull request #38674 from madmiraal/fix-physicsw-warning-3.2
Browse files Browse the repository at this point in the history
[3.2] Fix 'physicsw' may be used uninitialized warning in csg_shape.cpp
  • Loading branch information
akien-mga authored May 11, 2020
2 parents 499e945 + b4302d0 commit 44c1c58
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions modules/csg/csg_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,31 @@ void CSGShape::_update_shape() {
}
}

//fill arrays
PoolVector<Vector3> physics_faces;
bool fill_physics_faces = false;
// Update collision faces.
if (root_collision_shape.is_valid()) {

PoolVector<Vector3> physics_faces;
physics_faces.resize(n->faces.size() * 3);
fill_physics_faces = true;
}
PoolVector<Vector3>::Write physicsw = physics_faces.write();

{
PoolVector<Vector3>::Write physicsw;
for (int i = 0; i < n->faces.size(); i++) {

int order[3] = { 0, 1, 2 };

if (n->faces[i].invert) {
SWAP(order[1], order[2]);
}

if (fill_physics_faces) {
physicsw = physics_faces.write();
physicsw[i * 3 + 0] = n->faces[i].vertices[order[0]];
physicsw[i * 3 + 1] = n->faces[i].vertices[order[1]];
physicsw[i * 3 + 2] = n->faces[i].vertices[order[2]];
}

root_collision_shape->set_faces(physics_faces);
}

//fill arrays
{
for (int i = 0; i < n->faces.size(); i++) {

int order[3] = { 0, 1, 2 };
Expand All @@ -363,12 +373,6 @@ void CSGShape::_update_shape() {
SWAP(order[1], order[2]);
}

if (fill_physics_faces) {
physicsw[i * 3 + 0] = n->faces[i].vertices[order[0]];
physicsw[i * 3 + 1] = n->faces[i].vertices[order[1]];
physicsw[i * 3 + 2] = n->faces[i].vertices[order[2]];
}

int mat = n->faces[i].material;
ERR_CONTINUE(mat < -1 || mat >= face_count.size());
int idx = mat == -1 ? face_count.size() - 1 : mat;
Expand Down Expand Up @@ -458,10 +462,6 @@ void CSGShape::_update_shape() {
root_mesh->surface_set_material(idx, surfaces[i].material);
}

if (root_collision_shape.is_valid()) {
root_collision_shape->set_faces(physics_faces);
}

set_base(root_mesh->get_rid());
}
AABB CSGShape::get_aabb() const {
Expand Down

0 comments on commit 44c1c58

Please sign in to comment.