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

Fix ccd enabled by default on Bullet bodies #43801

Merged
merged 1 commit into from
Dec 3, 2020

Conversation

pouleyKetchoupp
Copy link
Contributor

Fix based on #42643 (comment)

It was due to main_shape_changed being called two times for each added body. The first time it disables ccd, which sets the internal ccd threshold to be 10000. The second time, it enables ccd again because the internal threshold is > 0.

Bodies are now consistently created with disabled ccd by default.

This was causing crashing asserts in Bullet when adding bodies in some scenarios, in btVector3::normalize():
btAssert(!fuzzyZero());

Copy link
Contributor

@madmiraal madmiraal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is that when CCD is disabled, Bullet's ccdMotionThreshold should be set to 0. not 10000.0:

btBody->setCcdMotionThreshold(10000.0);

First, it defaults to 0.:

Second, if it's 0, CCD is not used:
if (getDispatchInfo().m_useContinuous && body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion)

modules/bullet/rigid_body_bullet.cpp Outdated Show resolved Hide resolved
modules/bullet/rigid_body_bullet.cpp Outdated Show resolved Hide resolved
@madmiraal
Copy link
Contributor

This was causing crashing asserts in Bullet when adding bodies in some scenarios, in btVector3::normalize():
btAssert(!fuzzyZero());

Crashing asserts will still happen with CCD enabled. A separate issue should be raised, because there is a problem with the way that Godot is configuring Bullet CCD.

@pouleyKetchoupp
Copy link
Contributor Author

pouleyKetchoupp commented Nov 25, 2020

This was causing crashing asserts in Bullet when adding bodies in some scenarios, in btVector3::normalize():
btAssert(!fuzzyZero());

Crashing asserts will still happen with CCD enabled. A separate issue should be raised, because there is a problem with the way that Godot is configuring Bullet CCD.

Good point, I'll open a ticket for the CCD issue.

Edit: Opened #43868

@pouleyKetchoupp
Copy link
Contributor Author

pouleyKetchoupp commented Nov 25, 2020

Concerning the way CCD is currently set (threshold of 10000 when disabled) I've decided to keep it this way for now, because this PR is about fixing the crashes that happen without CCD, with minimal changes to current settings.

Edit:
Nevermind this, I had seen some parts of Bullet code that use the threshold without checking if it's 0, but after checking again it looks like it's only in special configurations for CCD, so I might as well simplify things and set it to 0 as you're proposing.

@pouleyKetchoupp
Copy link
Contributor Author

@AndreaCatania Do you remember why you set the CCD threshold to 10000 instead of 0 when CCD is disabled in PR #28595?

For now, I'm going to set it to 0 to make things more consistent, but let us know if it was solving a specific issue. Looking at Bullet code it shouldn't make a difference in behavior.

It was due to main_shape_changed being called two times for each
added body. The first time it disables ccd, which sets the internal ccd
threshold to be 10000. The second time, it enables ccd again because
the internal threshold is > 0.

Bodies are now consistently set with a ccd threshold of 0 when ccd is
disabled.

This was causing crashing asserts in Bullet when adding bodies in some
scenarios, in btVector3::normalize():
btAssert(!fuzzyZero());

These crashes will still happen with ccd enabled.
@akien-mga akien-mga merged commit 5861bac into godotengine:master Dec 3, 2020
@akien-mga
Copy link
Member

Thanks!

@akien-mga
Copy link
Member

Cherry-picked for 3.5.

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants