Skip to content

Commit 355919e

Browse files
Update code to silence modern compiler warnings (#657)
There were a number of uninitialized warnings (particularly with Eigen vectors). This initializes them so there's no complaints. There was also some compiler confusion about a polymorphic type (NaiveCollisionManager()). Simply replaced a pointer to the heap with an object on the stack.
1 parent da430b1 commit 355919e

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

include/fcl/narrowphase/detail/primitive_shape_algorithm/box_box-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ int boxBox2(
262262
// edge-edge. It is unclear why edge-edge contact receives this 5% penalty.
263263
// Someone should document this.
264264
const S fudge_factor = S(1.05);
265-
Vector3<S> normalC;
265+
// Dummy initialization; either it gets initialized below, or we bail out.
266+
Vector3<S> normalC = Vector3<S>::Zero();
266267
S s, s2, l;
267268
int invert_normal, code;
268269

include/fcl/narrowphase/detail/primitive_shape_algorithm/halfspace-inl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ bool convexHalfspaceIntersect(const Convex<S>& s1, const Transform3<S>& tf1,
504504
{
505505
Halfspace<S> new_s2 = transform(s2, tf2);
506506

507-
Vector3<S> v;
508507
S depth = std::numeric_limits<S>::max();
508+
Vector3<S> v = Vector3<S>::Constant(std::numeric_limits<S>::infinity());
509509

510510
// Note: There are two issues with this for loop:
511511
// 1. We are transforming *every* vertex in the convex. That's a waste.
@@ -550,7 +550,8 @@ bool convexHalfspaceIntersect(const Convex<S>& convex_C,
550550
std::vector<ContactPoint<S>>* contacts) {
551551
Halfspace<S> half_space_C = transform(half_space_H, X_FC.inverse() * X_FH);
552552

553-
Vector3<S> p_CV_deepest;
553+
Vector3<S> p_CV_deepest =
554+
Vector3<S>::Constant(std::numeric_limits<S>::infinity());
554555
S min_signed_distance = std::numeric_limits<S>::max();
555556

556557
// TODO: Once we have an efficient "support vector" implementation for Convex

include/fcl/narrowphase/detail/primitive_shape_algorithm/plane-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ bool convexPlaneIntersect(const Convex<S>& s1, const Transform3<S>& tf1,
645645
{
646646
Plane<S> new_s2 = transform(s2, tf2);
647647

648-
Vector3<S> v_min, v_max;
648+
Vector3<S> v_min = Vector3<S>::Constant(std::numeric_limits<S>::infinity());
649+
Vector3<S> v_max = -v_min;
649650
S d_min = std::numeric_limits<S>::max(), d_max = -std::numeric_limits<S>::max();
650651

651652
for (const auto& vertex : s1.getVertices())

include/fcl/narrowphase/detail/primitive_shape_algorithm/sphere_triangle-inl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ bool sphereTriangleIntersect(const Sphere<S>& s, const Transform3<S>& tf,
156156
bool is_inside_contact_plane = (distance_from_plane < radius_with_threshold);
157157

158158
bool has_contact = false;
159-
Vector3<S> contact_point;
159+
Vector3<S> contact_point =
160+
Vector3<S>::Constant(std::numeric_limits<S>::quiet_NaN());
160161
if(is_inside_contact_plane)
161162
{
162163
if(projectInTriangle(P1, P2, P3, normal, center))

test/narrowphase/detail/primitive_shape_algorithm/test_sphere_box.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ void QueryWithVaryingWorldFrames(
597597
auto evaluate_all = [&R_BS, query_eval](
598598
const std::vector<TestConfiguration<S>>& configs,
599599
const Transform3<S>& X_FB) {
600-
for (const auto config : configs) {
600+
for (const auto& config : configs) {
601601
query_eval(config, X_FB, R_BS, Eps<S>::value());
602602
}
603603
};

test/narrowphase/detail/primitive_shape_algorithm/test_sphere_cylinder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ void QueryWithVaryingWorldFrames(
784784
auto evaluate_all = [&R_CS, query_eval](
785785
const std::vector<TestConfiguration<S>>& configs,
786786
const Transform3<S>& X_FC) {
787-
for (const auto config : configs) {
787+
for (const auto& config : configs) {
788788
query_eval(config, X_FC, R_CS, Eps<S>::value());
789789
}
790790
};

test/test_fcl_broadphase_distance.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ void broad_phase_distance_test(S env_scale, std::size_t env_size, std::size_t qu
443443

444444
std::vector<CollisionObject<S>*> query;
445445

446-
BroadPhaseCollisionManager<S>* manager = new NaiveCollisionManager<S>();
446+
NaiveCollisionManager<S> manager;
447447
for(std::size_t i = 0; i < env.size(); ++i)
448-
manager->registerObject(env[i]);
449-
manager->setup();
448+
manager.registerObject(env[i]);
449+
manager.setup();
450450

451451
while(1)
452452
{
@@ -459,7 +459,7 @@ void broad_phase_distance_test(S env_scale, std::size_t env_size, std::size_t qu
459459
for(std::size_t i = 0; i < candidates.size(); ++i)
460460
{
461461
DefaultCollisionData<S> query_data;
462-
manager->collide(candidates[i], &query_data, DefaultCollisionFunction);
462+
manager.collide(candidates[i], &query_data, DefaultCollisionFunction);
463463
if(query_data.result.numContacts() == 0)
464464
query.push_back(candidates[i]);
465465
else
@@ -470,8 +470,6 @@ void broad_phase_distance_test(S env_scale, std::size_t env_size, std::size_t qu
470470
if(query.size() == query_size) break;
471471
}
472472

473-
delete manager;
474-
475473
std::vector<BroadPhaseCollisionManager<S>*> managers;
476474

477475
managers.push_back(new NaiveCollisionManager<S>());

test/test_fcl_simple.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ void test_Vec_nf_test()
106106
std::cout << c.transpose() << std::endl;
107107

108108
VectorN<S, 4> upper, lower;
109-
for(int i = 0; i < 4; ++i)
109+
for(int i = 0; i < 4; ++i) {
110110
upper[i] = 1;
111+
lower[i] = -1;
112+
}
111113

112114
VectorN<S, 4> aa = VectorN<S, 4>(1, 2, 1, 2);
113115
std::cout << aa.transpose() << std::endl;

0 commit comments

Comments
 (0)