-
Notifications
You must be signed in to change notification settings - Fork 361
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Misaligned ABI when using JPH_DOUBLE_PRECISION causes a problem on the VirtualCharacter #1071
Comments
The only thing I can think of is that you have a mismatch in the JPH_DOUBLE_PRECISION define between the two projects. The CharacterVirtual constructor literally just puts the position and rotation as a member and GetPosition/Rotation returns that member. By stepping through the disassembly you can see if both sides use 256 bit registers and if the offsets where it stores/gets the values are the same. |
I wrote |
I would say this is a typical symptom of a mismatch in preprocessor defines, but maybe there are other compiler flags that affect the class layout. |
And have you done the same in the Jolt code to verify that it too is being compiled with JPH_DOUBLE_PRECISION? |
Yeah, I totally agree. I think
Yes, I just tested it again. I've added the following static function, inside the CharacterVirtual.cpp, and it returns true, when called from UnrealEngine. This is the command I use to compile jolt:
I wonder, is it possible to get the list of all the preprocessor-defines defined by CMake? |
It looks like you're generating a visual studio project, so wouldn't right clicking the project, Properties, C++, Command Line tell you the exact command line that is used (including all preprocessor defines)? |
This is the command line defines:
This is the check on the Unreal Engine side.
I assume these are the only "external" defines which are required to have on the Unreal Engine side too. Everything seems correct till this point. I wonder if the library linking is broken instead, somehow. |
@jrouwe using this function:
Then, I've duplicated that function inside a jolt lib CPP file and compared the two strings:
As you can notice, even if jolt is compiled using Anyway, I've removed the extra and not used preprocessor define |
If I run cmake with your options (with I use a MSVC plugin called Struct Layout to display the layout of the class and this agrees: However in MSVC 17.9 they added a tool called 'Memory Layout' which agrees with your measurement: The difference is in the beginning of the class, Struct Layout aligns the base class RefTarget<...> to 16 bytes: While Memory Layout does not: If I add Switching to MSVC 2019 or a MSVC Clang-17 build gives me the same trace output. Running the same code on Linux with clang however gives me It appears that MSVC aligns the first member of the class to the largest alignment of any of the members of the class which doesn't really make sense to me, but a simple experiment in godbolt confirms it. If you switch from MSVC to clang x64 18 and suppress a warning
Running either clang++.exe or clang-cl.exe on Windows don't trigger this error, so it must be how the windows ABI is defined. I have no idea what Unreal does to negate this, but you could try the test code in Unreal to see what it does and you could try finding out what |
Thanks a lot for the detailed answer. The misalignment starts from
I think the problem can be fixed by using the same toolchain that unreal is using to compile Jolt. I just need to figure out how, now. |
Ok, in the mean time I reported the problem with the Memory Layout tool to Microsoft here. Converting this to a discussion as I don't think there's a bug in Jolt. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hello, I'm integrating Jolt into UE5 and while integrating the
VirtualCharacter
I've encountered a weird crash.After a bunch of tests I've noticed that
CharacterVirtual->GetPosition();
andCharacterVirtual->GetRotation();
returned a different value than the one specified during the initialization so I added two checks to verify that.The above checks are not satisfied. I suspected an ABI misalignment. I've then found that compiling the library with double precision disabled (
-DDOUBLE_PRECISION=OFF
) fixed the issue.Consider that on the app side I've defined
JPH_DOUBLE_PRECISION
usingPublicDefinitions.Add("JPH_DOUBLE_PRECISION=1");
so I'm not sure what is causing this issue. Do you have any idea?The text was updated successfully, but these errors were encountered: