jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.55k stars 425 forks source link

Compilation fails with g++ on Ubuntu 22.04 #1156

Closed Skroopa closed 3 months ago

Skroopa commented 3 months ago

Can't compile with g++ on Ubuntu 22.04 in Docker:

#0 38.68 In file included from /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:7:
#0 38.68 /JoltPhysics/Build/../Jolt/Physics/SoftBody/SoftBodyMotionProperties.h: In member function 'virtual void JPH::SoftBodyMotionProperties::DetermineCollidingShapes(const JPH::SoftBodyUpdateContext&, const JPH::PhysicsSystem&, const JPH::BodyLockInterface&)::Collector::AddHit(const JPH::BodyID&)':
#0 38.68 /JoltPhysics/Build/../Jolt/Physics/SoftBody/SoftBodyMotionProperties.h:166:16: error: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mOriginalAngularVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' may be used uninitialized in this function [-Werror=maybe-uninitialized]
#0 38.68   166 |         struct CollidingShape
#0 38.68       |                ^~~~~~~~~~~~~~
#0 38.68 /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:152:56: note: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mOriginalAngularVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' was declared here
#0 38.68   152 |                                         CollidingShape cs;
#0 38.68       |                                                        ^~
#0 38.68 In file included from /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:7:
#0 38.68 /JoltPhysics/Build/../Jolt/Physics/SoftBody/SoftBodyMotionProperties.h:166:16: error: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mOriginalLinearVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' may be used uninitialized in this function [-Werror=maybe-uninitialized]
#0 38.68   166 |         struct CollidingShape
#0 38.68       |                ^~~~~~~~~~~~~~
#0 38.68 /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:152:56: note: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mOriginalLinearVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' was declared here
#0 38.68   152 |                                         CollidingShape cs;
#0 38.68       |                                                        ^~
#0 38.68 In file included from /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:7:
#0 38.68 /JoltPhysics/Build/../Jolt/Physics/SoftBody/SoftBodyMotionProperties.h:166:16: error: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mAngularVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' may be used uninitialized in this function [-Werror=maybe-uninitialized]
#0 38.68   166 |         struct CollidingShape
#0 38.68       |                ^~~~~~~~~~~~~~
#0 38.68 /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:152:56: note: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mAngularVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' was declared here
#0 38.68   152 |                                         CollidingShape cs;
#0 38.68       |                                                        ^~
#0 38.68 In file included from /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:7:
#0 38.68 /JoltPhysics/Build/../Jolt/Physics/SoftBody/SoftBodyMotionProperties.h:166:16: error: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mLinearVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' may be used uninitialized in this function [-Werror=maybe-uninitialized]
#0 38.68   166 |         struct CollidingShape
#0 38.68       |                ^~~~~~~~~~~~~~
#0 38.68 /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:152:56: note: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mLinearVelocity.JPH::Vec3::<anonymous>.JPH::Vec3::<unnamed union>::mValue' was declared here
#0 38.68   152 |                                         CollidingShape cs;
#0 38.68       |                                                        ^~
#0 38.68 /JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp:152:56: error: 'cs.JPH::SoftBodyMotionProperties::CollidingShape::mInvMass' may be used uninitialized in this function [-Werror=maybe-uninitialized]
#0 38.98 [ 49%] Building CXX object CMakeFiles/Jolt.dir/JoltPhysics/Jolt/Physics/SoftBody/SoftBodySharedSettings.cpp.o
#0 39.24 cc1plus: all warnings being treated as errors
#0 39.26 [ 50%] Building CXX object CMakeFiles/Jolt.dir/JoltPhysics/Jolt/Physics/StateRecorderImpl.cpp.o
#0 39.29 make[2]: *** [CMakeFiles/Jolt.dir/build.make:1629: CMakeFiles/Jolt.dir/JoltPhysics/Jolt/Physics/SoftBody/SoftBodyMotionProperties.cpp.o] Error 1
#0 39.29 make[2]: *** Waiting for unfinished jobs....
#0 44.02 make[1]: *** [CMakeFiles/Makefile2:89: CMakeFiles/Jolt.dir/all] Error 2
#0 44.02 make: *** [Makefile:146: all] Error 2

Any ideas how to fix this properly?

jrouwe commented 3 months ago

What version of Jolt are you using? Can you check you have https://github.com/jrouwe/JoltPhysics/commit/178141555fe442af3209156bf4b7945ff521bf34?

Skroopa commented 3 months ago

latest master and I can see -Wunused-parameter, yes. Adding JPH_GCC_SUPPRESS_WARNING("-Wmaybe-uninitialized") helps tho, and after further investigation I don't think we will have problems, if we will add it...

jrouwe commented 3 months ago

Sorry, I made a mistake: -Wunused-parameter != -Wmaybe-uninitialized. I thought I had seen the same error before.

Adding JPH_GCC_SUPPRESS_WARNING("-Wmaybe-uninitialized") will work indeed, but that turns off a useful warning completely. I've created a better fix here: #1159

I'm on GCC 14.0.1 and the warning doesn't trigger for me so I cannot test if this fixes it. Can you verify?

Also I'd be interested why it triggers for you. Which version of GCC are you using? With which flags are you building Jolt?

Skroopa commented 3 months ago

Yes, I found out that error with CollidingShape occurs if INTERPROCEDURAL_OPTIMIZATION is OFF. The patch #1159 doesn't help to fix it. clang version built without errors even if this flag is ON.

USE_AVX, USE_AVX2, USE_AVX512, USE_LZCNT, USE_TZCNT, USE_F16C are OFF and CROSS_PLATFORM_DETERMINISTIC is ON, g++ version 11.4.0 (part of build-essential package).

jrouwe commented 3 months ago

I can reproduce it now. #1159 does fix the warning, but there are other similar warnings that trigger. I've globally disabled the warning now in #1166 and I'll merge it once it goes through the build.