Encountered a deterministic problem of CharacterVirtual::Contact::mContactNormal on the android platform #1098
Unanswered
tianxing113
asked this question in
Q&A
Replies: 1 comment
-
Thanks for the detailed report (these things are very difficult to analyze so you saved me a lot of work)! I've created a fix in #1100. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I used the snapshot information recorded by StateRecorder to test deterministic of multiple different platforms. The four platforms are: win/x64, linux/x64, macOS/x64, and android/arm64. After running the game, it was found that the snapshot information of CharacterVirtual on the android platform is different from that of the other platforms. Upon deserializing the snapshot information, it was discovered that only the value of CharacterVirtual::Contact::mContactNormal is different from the other platforms. The other platforms have the value (0, 1, 0), while the android platform has the value (-0, 1, -0). The following is an excerpt from the test record:
Android:
{ GroundState: 0,GroundBodyID: 16777216,GroundSubShapeID: 4294967295,GroundPosition: (1.96999, 1, -6.228),GroundNormal: (0, 1, 0),GroundVelocity: (0, 0, 0),Position: (1.96999, 1, -6.228),Rotation: (0, 1, 0, 0),LinearVelocity: (0, -0.647415, 0),LastDeltaTime: 0.0659943,MaxHitsExceeded: 0,ActiveContacts: [(Position: (1.96999, 1, -6.228),LinearVelocity: (0, 0, 0),ContactNormal: (-0, 1, -0),SurfaceNormal: (0, 1, 0),Distance: -1.86265e-08,Fraction: 0,BodyB: 16777216,SubShapeIDB: 4294967295,MotionTypeB: 0,HadCollision: 1,WasDiscarded: 0,CanPushCharacter: 1,)] }
Others:
{ GroundState: 0,GroundBodyID: 16777216,GroundSubShapeID: 4294967295,GroundPosition: (1.96999, 1, -6.228),GroundNormal: (0, 1, 0),GroundVelocity: (0, 0, 0),Position: (1.96999, 1, -6.228),Rotation: (0, 1, 0, 0),LinearVelocity: (0, -0.647415, 0),LastDeltaTime: 0.0659943,MaxHitsExceeded: 0,ActiveContacts: [(Position: (1.96999, 1, -6.228),LinearVelocity: (0, 0, 0),ContactNormal: (0, 1, 0),SurfaceNormal: (0, 1, 0),Distance: -1.86265e-08,Fraction: 0,BodyB: 16777216,SubShapeIDB: 4294967295,MotionTypeB: 0,HadCollision: 1,WasDiscarded: 0,CanPushCharacter: 1,)] }
I reviewed the source code and found that Contact::mContact is only assigned a value within CharacterVirtual::sFillContactProperties:
outContact.mContactNormal = -inResult.mPenetrationAxis.NormalizedOr(Vec3::sZero()); here, the negation operation of Vec3 is used.
The code for Vec3's negation operation is as follows:
Vec3 Vec3::operator - () const
{
#if defined(JPH_USE_SSE)
return _mm_sub_ps(_mm_setzero_ps(), mValue);
#elif defined(JPH_USE_NEON)
return vnegq_f32(mValue);
#else
return Vec3(-mF32[0], -mF32[1], -mF32[2]);
#endif
}
Android uses NEON instruction, while other platforms use SSE instruction. So I suspect that the discrepancy might be due to the different outcomes of the negation operation on the floating-point number zero resulting from these two sets of instructions.
Beta Was this translation helpful? Give feedback.
All reactions