-
Notifications
You must be signed in to change notification settings - Fork 830
Description
Hello, found a strange issue that only seems to happen when I run my code in release mode.
Here's a oversimplified overview of what I'm doing:
I decided to control movement of certain objects using 'normal' PxRigidDynamic velocities, but lock their angular velocity to zero and rotate them through game logic on a frame-by-frame basis, manually using setGlobalPose.
For some reason, the Debug-build behaves as I would expect it to: Rotation is updated and the actor moves and collides with stuff as I'd expect it.
Release build, however, has a strange issue: Reported velocity from the body is being updated (ei I see correct values and if in air, the gravity is also doing it's thing), but the actor is frozen in-place.
I'm also using the double-buffering feature and here's what the relevant part of the whole loop looks like:
0. For PxRigidDynamic, I check the transform-pose on the game-logic-side;
- If the pose matches what I got from the PxRigidDynamic on the previous update, nothing happens;
- Otherwise, I set pose via setGlobalPose;
- If velocity has been modified by game-code, I add the difference in velocity using addForce(deltaV, physx::PxForceMode::eVELOCITY_CHANGE);
- If angular velocity was altered, I'm also updating it.
- Once the above is done for all dynamic bodies, I invoke m_scene->fetchResults(true) and m_scene->simulate(deltaT, nullptr, cratchBuff, scratchSize);
- After that, I go back to the actors and retrieve the information about current velocity, angular velocity and the pose and update the corresponding logic-side transform pose to match the one from the actor;
- Angular velocity can be applied if changed once more (in this situation, it is not).
The code is from my engine, which happens to be open-source and I can provide the exact implementation details:
Steps 0 to 4 are on lines 164 to 180: https://github.com/TheDonsky/Jimara/blob/main/__Source__/Jimara/Components/Physics/Rigidbody.cpp
Step 5 is on lines 210 to 264: https://github.com/TheDonsky/Jimara/blob/main/__Source__/Jimara/Environment/Scene/Physics/PhysicsContext.cpp
Steps 6-7 happen on lines 183-217 here: https://github.com/TheDonsky/Jimara/blob/main/__Source__/Jimara/Components/Physics/Rigidbody.cpp
PhysX-specific code for the scene fetchResults and simulate calls is within this file: https://github.com/TheDonsky/Jimara/blob/main/__Source__/Jimara/Physics/PhysX/PhysXScene.cpp
Wrapper on top of the PxRigidDynamic is implemented here: https://github.com/TheDonsky/Jimara/blob/main/__Source__/Jimara/Physics/PhysX/PhysXDynamicBody.cpp
Here's a video, demonstrating the issue (Y rotation is not locked, because I'm also showing that the rotation-set is the only variable): https://youtu.be/yMl4NcmDB2w
Additionally, I'm using a static-lib version of PhysX if that matters;
I also know that 5.0 and forward, double-buffering is no longer supported, but I rely on it and don't currently have the time to upgrade the PhysX version to 5.0 and do the whole refactor that it entails (probably something for the future).
Sometime in the next couple of weeks I can squeeze-out additional time if needed to create a contained demo code with just physX actors and a single file, or something like that, if you require it.
Thank you in advance, and hope to hear back from you.