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

Handle dynamic bodies without mass better, so user cant easily make mistake #268

Open
viblo opened this issue Jan 17, 2025 · 1 comment
Open

Comments

@viblo
Copy link
Owner

viblo commented Jan 17, 2025

As clear from #267 and #226 and others its really easy to forget to set a valid mass on a body. And when it happens you will get a difficult-to-understand error, most common is debug draw failure because of NaNs. This must be possible to handle better.

@viblo
Copy link
Owner Author

viblo commented Jan 17, 2025

The problem with this error is that is not easy where to stop the 0 mass.

  • Its valid to create a body with 0 mass, if you attach a shape with mass to it before simulation step.
  • Chipmunk contains already an assert that checks that if a shape attached to a body has mass >0, then the body have a valid mass calculated.
  • I dont want to have to check the mass every call to step. I do however think its reasonable to require that bodies have >0 mass once the simulation is run even if that is not the case now.
  • Even if debug draw had a better error message, there's no guarantee that debug draw is used, so does not solve it fully.
  • Bodies are not fully connected to the shapes before they are added to a space.

To be able to check for this the API needs to be more strict.

The least breaking solution I can think of is:
Restrict so that if you have a body with 0 mass, add a shape to it and add the shape to the space, at this time the body must get a mass > 0. This means you cant do a 0 mass body, add 0 mass shape to it, add both to the space, and afterwards make a 2nd shape with mass > 0 to fix it.

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

No branches or pull requests

1 participant