jrouwe/JoltPhysics

Size of `TransformedShape` and `Body` is not as expected on ARM32 with double-precision

Closed this issue · 1 comments

mihe commented

When compiling with DOUBLE_PRECISION=YES for ARM32 Android, I'm met with the following errors:

Jolt/Physics/Collision/TransformedShape.h:191:1: error: static_assert failed due to requirement 'sizeof(JPH::TransformedShape) == 96' "Not properly packed"
static_assert(sizeof(TransformedShape) == JPH_IF_SINGLE_PRECISION_ELSE(64, 96), "Not properly packed");
^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jolt/Physics/Body/Body.h:385:1: error: static_assert failed due to requirement 'sizeof(JPH::Body) == 160' "Body size is incorrect"
static_assert(sizeof(Body) == JPH_IF_SINGLE_PRECISION_ELSE(128, 160), "Body size is incorrect");
^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I've only looked into TransformedShape so far, but I assume the issue is similar with Body.

Basically, it seems like this:

#define JPH_VECTOR_ALIGNMENT 8 // 32-bit ARM does not support aligning on the stack on 16 byte boundaries
#define JPH_DVECTOR_ALIGNMENT 8

... coupled with the fact that ARM32 uses 32-bit pointers, leads to TransformedShape having a total size of 80 bytes (including a 4-byte padding at the end), which obviously differs from the 96 bytes expected in this assertion:

static_assert(sizeof(TransformedShape) == JPH_IF_SINGLE_PRECISION_ELSE(64, 96), "Not properly packed");

Yes, 32 bit and doubles haven't been tested yet. Doesn't seem hard to fix this though.