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.74k stars 452 forks source link

Version mismatch and other bizarre problems on macOS / XCode #923

Closed SheridanR closed 9 months ago

SheridanR commented 9 months ago

Hello,

I hate to be "that guy" but I'm struggling to get jolt to link with my project and work at all on macOS/XCode. I'm compiling Jolt from the last release (4.0.2) using the cmake_macos_xcode.sh script, which seemingly produces no errors and warnings, and I can run the included Hello World example just fine. However, if I link my compiled libJolt.a to my own project and build an equivalent Hello World, Jolt immediately asserts in RegisterTypes() with this message: Version mismatch, make sure you compile the client code with the same Jolt version and compiler definitions! Okay, seems straight-forward enough, but to my knowledge I've copied all of the build flags from jolt's auto-generated XCode project to my own (making sure to keep ffp-model=precise and std=c++17 for instance), and I still get this error no matter what.

For my own sanity, I tried disabling the version check in RegisterTypes() as an experiment, but every call to PhysicsSystem::Init() after that crashes with very peculiar symptoms, eg failing basic asserts around allocating std::vectors for physics bodies (yeah, I tried passing in very conservative values here) or even triggering unguarded segfaults elsewhere in PhysicsSystem::Init(). Okay, something is obviously very amiss here.

Anyway, I apologize for the basic nature of this question but since I've been over this for a few hours and I'm not making progress, I figured it's worth it to at least ask if anyone has suggestions for me to try. If I manage to figure out the cause of my problem on my own, I will for sure update this thread as well.

SheridanR commented 9 months ago

Okay, a little more digging and I found that I missed the preprocessor macros that cmake was injecting the xcode project with. In my case they were JPH_PROFILE_ENABLED and JPH_DEBUG_RENDERER. Since the version code is constructed by a bitmask it would be nice if the Version mismatch error was more verbose about which preprocessor flags are missing. I was extra confused because I wasn't passing either of these flags into the cmake build script, they were just on by default and I didn't pick up on that.

In any event, my project works now. I hope this helps some other knuckle-head in the future :)