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

[3.x] Fix physics BVH broadphase update when changing collision layer/mask #54108

Merged

Conversation

pouleyKetchoupp
Copy link
Contributor

The BVH implementation is not checking collision layers on existing pairs on move like other physics broadphases do.

This is solved by adding a new call to trigger pair callbacks again so the physics engine can check layers again (specific to the BVH version, other broadphase implementations just trigger a move like before).

It looks like a lot of file changes but active code changes are actually well contained to limit potential regressions.
Fixes #53997 for 3.4.
For 4.0 and 3.5, a cleaner approach will be used but it will be a wider change that will need more time for tests (see #53997 (comment)).

typename BVHTREE_CLASS::ItemExtra &exb = tree._extra[p_to.id()];

// if the userdata is the same, no collisions should occur
if ((exa.userdata == exb.userdata) && exa.userdata) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lawnjelly I'm not 100% sure this condition is needed here, same with _handle_sort above, but I've copied them from other functions that deal with pairing and it doesn't seem that it hurts.

Copy link
Member

Choose a reason for hiding this comment

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

This was something I had to copy from the original octree, there were some cases were duplicates were added by the client code, and they caused crashes if they collided with themselves. So it probably is safer to keep it in.

The BVH implementation is not checking collision layers on existing
pairs on move like other physics broadphases do.

This is solved by adding a new call to trigger pair callbacks again so
the physics engine can check layers again (specific to the BVH version,
other broadphase implementations just trigger a move like before).
@pouleyKetchoupp pouleyKetchoupp force-pushed the fix-bvh-update-collision-layer-3.x branch from 5ef89fe to 48144ed Compare October 21, 2021 23:53
@lawnjelly
Copy link
Member

Looks good in terms of the code, I just want to test it, couldn't download the artifacts for some reason so will have to build from source.

Copy link
Member

@lawnjelly lawnjelly left a comment

Choose a reason for hiding this comment

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

Have now built it and it seems to work fine. Is maybe not as efficient as it can be but will do to fix it until we have a chance to do a bigger refactor. 👍

@akien-mga akien-mga merged commit e81c3fb into godotengine:3.x Oct 22, 2021
@akien-mga
Copy link
Member

Thanks!

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