2
8
Fork
You've already forked Chipmunk2D
3

Fix INFINITY checks for fast-math compatibility #259

Open
tguerin wants to merge 1 commit from tguerin/Chipmunk2D:fix/infinite_loop into master
pull from: tguerin/Chipmunk2D:fix/infinite_loop
merge into: slembcke:master
slembcke:master
slembcke:6.2.x
slembcke:glfw3
slembcke:cpp
slembcke:GL3
slembcke:GLFW-refactor
slembcke:custom-contact
slembcke:UnityTemp
slembcke:6.1.x
slembcke:speculative
slembcke:surfacev
First-time contributor
Copy link

I'm the maintainer of Chipmunk2D ffi and my github PR was skipped during the move of the project.

Problem:
The sleeping mechanism froze when enabled because -ffast-math (enabled by default in Release builds) optimizes away direct INFINITY comparisons, causing (sleepTimeThreshold != INFINITY) to always evaluate incorrectly.

Solution:
Replaced all INFINITY comparisons with isfinite()/isinf() across the codebase:

cpSpaceComponent.c: Fixed sleep check in cpSpaceProcessComponents
cpBody.c: Fixed mass and idle time checks
cpSpaceStep.c: Fixed collision filtering
cpBB.h: Fixed segment intersection check
ChipmunkDemo.c: Fixed kinetic energy and point query checks

I'm the maintainer of [Chipmunk2D ffi](https://pub.dev/packages/chipmunk2d_physics_ffi/versions) and my github PR was skipped during the move of the project. **Problem:** The sleeping mechanism froze when enabled because -ffast-math (enabled by default in Release builds) optimizes away direct INFINITY comparisons, causing (sleepTimeThreshold != INFINITY) to always evaluate incorrectly. **Solution:** Replaced all INFINITY comparisons with isfinite()/isinf() across the codebase: cpSpaceComponent.c: Fixed sleep check in cpSpaceProcessComponents cpBody.c: Fixed mass and idle time checks cpSpaceStep.c: Fixed collision filtering cpBB.h: Fixed segment intersection check ChipmunkDemo.c: Fixed kinetic energy and point query checks
First-time contributor
Copy link

Supposedly, isnan() and isinf() are also UB with -ffast-math.

The solution that worked for me was to use -ffast-math -fno-finite-math-only.

Supposedly, `isnan()` and `isinf()` are also UB with `-ffast-math`. The solution that worked for me was to use `-ffast-math -fno-finite-math-only`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix/infinite_loop:tguerin-fix/infinite_loop
git switch tguerin-fix/infinite_loop

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff tguerin-fix/infinite_loop
git switch tguerin-fix/infinite_loop
git rebase master
git switch master
git merge --ff-only tguerin-fix/infinite_loop
git switch tguerin-fix/infinite_loop
git rebase master
git switch master
git merge --no-ff tguerin-fix/infinite_loop
git switch master
git merge --squash tguerin-fix/infinite_loop
git switch master
git merge --ff-only tguerin-fix/infinite_loop
git switch master
git merge tguerin-fix/infinite_loop
git push origin master
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
slembcke/Chipmunk2D!259
Reference in a new issue
slembcke/Chipmunk2D
No description provided.
Delete branch "tguerin/Chipmunk2D:fix/infinite_loop"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?