Skip to content
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

Removing a rigidbody and re-adding it to the scene results in errors and the rigidbody disappearing #10074

Closed
cart opened this issue Aug 4, 2017 · 13 comments

Comments

@cart
Copy link
Contributor

cart commented Aug 4, 2017

Operating system or device - Godot version:
Arch Linux - 211dfa6

Issue description:
Whenever I remove a RigidBody (with mode == RigidBody.MODE_RIGID) from a scene, then re-add it to the scene, I get the following errors (spammed repeatedly):

Condition 'p_axis.is_normalized() == false' is true
Condition 'determinant() == 0' is true

The rigidbody also disappears.

The errors are there for transform validation and I agree that they should be there, but I would expect a rigidbody removed from the tree with a valid transform to re-enter the tree with a valid transform. This wasn't an issue in older versions of godot (early 3.0 and 2.1) and it breaks key functionality in my game. This feels like a common use of rigidbodies, so I'm guessing I won't be the only one affected.

Steps to reproduce:

  1. create a scene with a rigidbody in it
  2. run the scene
  3. remove the rigidbody from the scene
  4. wait
  5. add the rigidbody back to the scene
  6. watch the rigidbody disappear and your debug console explode with error messages

Link to minimal example project:
rigidbody_readd.zip

@kubecz3k
Copy link
Contributor

kubecz3k commented Aug 4, 2017

How is the rigidbody disappearing? Is it flying through the terrain maybe?
edit: I have checked, it seems like after readding its in proper position for one frame, and then it's falling down extremely fast (around one-two godot meters per single frame). And yes through terrain as well.

@kubecz3k
Copy link
Contributor

kubecz3k commented Aug 4, 2017

I'm able to reproduce in 7ac50b5

@kubecz3k
Copy link
Contributor

kubecz3k commented Aug 4, 2017

for those who read issues only from email: it seems like after readding its in proper position for one frame, and then it's falling down extremely fast (around one-two godot meters per single frame). And yes through terrain as well.

@ghost
Copy link

ghost commented Aug 5, 2017

Not sure what the problem exactly is but those errors only reveal an existing buggy behavior. Removing those won't fix the underlying bug.

@cart
Copy link
Contributor Author

cart commented Aug 5, 2017

I agree that the error messages should not be removed and that they are only symptoms of the problem. I said something similar in my original post, but I apologize if I wasn't clear enough.

@ghost
Copy link

ghost commented Aug 5, 2017

Yeah, what I wanted to say is that I don't think things were working totally correctly in earlier releases.

@cart
Copy link
Contributor Author

cart commented Aug 6, 2017

According to my definition of "totally correct" it was. I ran the project above on 9cdd364 (i just picked an early version of 3.0 at random) and it behaved as expected. The rigidbody dropped, was removed, was readded, and it continued dropping without errors at the same velocity that it was removed at.

@cart cart closed this as completed Aug 6, 2017
@cart cart reopened this Aug 6, 2017
@cart
Copy link
Contributor Author

cart commented Aug 6, 2017

Sorry .. I fat-fingered the close issue button 😄

@ghost
Copy link

ghost commented Aug 6, 2017

If everything was completely OK, there wouldn't be a singular matrix though

@cart
Copy link
Contributor Author

cart commented Aug 6, 2017

I think we are in agreement then. Again, I am not asserting that the problem is the error messages. I am asserting that recent changes in godot resulted in issues that were not there in the past (non singular singular matrices when readding rigidbodies).

Just to prove my point, I backported the current matrix3.cpp to 9cdd364 and there still weren't any validation errors or behavior changes in the demo project above, which should mean that at that point in time, there was nothing wrong with the transform's basis.

@ghost
Copy link

ghost commented Aug 6, 2017

Just gave it a quick try with gdb, the axis and angle are apparently NaN.

REMOVED RIGIDBODY
READDED RIGIDBODY

Thread 1 "godot.x11.tools" hit Breakpoint 1, Basis::set_axis_angle (this=0x7fffffffd390, p_axis=..., p_phi=-nan(0x400000)) at core/math/matrix3.cpp:643
643     void Basis::set_axis_angle(const Vector3 &p_axis, real_t p_phi) {
(gdb) bt
#0  Basis::set_axis_angle (this=0x7fffffffd390, p_axis=..., p_phi=-nan(0x400000)) at core/math/matrix3.cpp:643
#1  0x000000010211414f in Basis::Basis (this=0x7fffffffd390, p_axis=..., p_phi=-nan(0x400000)) at core/math/matrix3.cpp:667
#2  0x0000000101ee51ba in BodySW::integrate_velocities (this=0x1041c0ab0, p_step=0.0166666675) at servers/physics/body_sw.cpp:594
#3  0x0000000101e9f00e in StepSW::step (this=0x103c25c80, p_space=0x10415deb0, p_delta=0.0166666675, p_iterations=8) at servers/physics/step_sw.cpp:270
#4  0x0000000101da7df7 in PhysicsServerSW::step (this=0x103c13880, p_step=0.0166666675) at servers/physics/physics_server_sw.cpp:1435
#5  0x0000000100abd269 in Main::iteration () at main/main.cpp:1577
#6  0x0000000100a99c87 in OS_X11::run (this=0x7fffffffd6d0) at platform/x11/os_x11.cpp:2128
#7  0x0000000100a90540 in main (argc=1, argv=0x7fffffffdbe8) at platform/x11/godot_x11.cpp:52
(gdb) p p_axis
$1 = (const Vector3 &) @0x7fffffffd378: {{{x = -nan(0x400000), y = -nan(0x400000), z = -nan(0x400000)}, coord = {-nan(0x400000), -nan(0x400000), -nan(0x400000)}}}
(gdb) p p_phi
$2 = -nan(0x400000)

RandomShaper added a commit to RandomShaper/godot that referenced this issue Aug 16, 2017
Now the shape in the physics server is unbound only when it's unparented from its body, because if it's unbound when just exiting the tree, a later readd would have the body shapeless in the server.

It's the same currently being done in 2D physics.

Fixes godotengine#10074.
@RandomShaper
Copy link
Member

Please check #10365.

Without it, after re-adding the body, BodySW::update_inertias() sees no shapes and thus inertia_tensor is left as all-zeroes so _inv_inertia goes to infinity.

@cart
Copy link
Contributor Author

cart commented Aug 16, 2017

Everything is working great now on my end. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants