slembcke/Chipmunk2D

Demo crashing in release mode [using GCC 13]

nathansmith117 opened this issue · 7 comments

The demos work fine in debug mode but just pause and crash in release mode.
I am on fedora 38 and using the newest version of chipmunk and I am compiling with gcc 13.1.1.

I can confirm that, the demo computes fine until the ballBody hits the ground.

I just built the 7.0.3 release on arch linux using gcc 13.2.1

(BTW: As far as I can tell this seems to be the only proper physics library written in pure C, which makes it quite unique and wonderful.)

here is my output:

Time is  0.00. ballBody is at ( 0.00, 15.00). It's velocity is ( 0.00,  0.00)
Time is  0.02. ballBody is at ( 0.00, 15.00). It's velocity is ( 0.00, -1.67)
Time is  0.03. ballBody is at ( 0.00, 14.97). It's velocity is ( 0.00, -3.33)
Time is  0.05. ballBody is at ( 0.00, 14.92). It's velocity is ( 0.00, -5.00)
Time is  0.07. ballBody is at ( 0.00, 14.83). It's velocity is ( 0.00, -6.67)
Time is  0.08. ballBody is at ( 0.00, 14.72). It's velocity is ( 0.00, -8.33)
Time is  0.10. ballBody is at ( 0.00, 14.58). It's velocity is ( 0.00, -10.00)
Time is  0.12. ballBody is at ( 0.00, 14.42). It's velocity is ( 0.00, -11.67)
Time is  0.13. ballBody is at ( 0.00, 14.22). It's velocity is ( 0.00, -13.33)
Time is  0.15. ballBody is at ( 0.00, 14.00). It's velocity is ( 0.00, -15.00)
Time is  0.17. ballBody is at ( 0.00, 13.75). It's velocity is ( 0.00, -16.67)
Time is  0.18. ballBody is at ( 0.00, 13.47). It's velocity is ( 0.00, -18.33)
Time is  0.20. ballBody is at ( 0.00, 13.17). It's velocity is ( 0.00, -20.00)
Time is  0.22. ballBody is at ( 0.00, 12.83). It's velocity is ( 0.00, -21.67)
Time is  0.23. ballBody is at ( 0.00, 12.47). It's velocity is ( 0.00, -23.33)
Time is  0.25. ballBody is at ( 0.00, 12.08). It's velocity is ( 0.00, -25.00)
Time is  0.27. ballBody is at ( 0.00, 11.67). It's velocity is ( 0.00, -26.67)
Time is  0.28. ballBody is at ( 0.00, 11.22). It's velocity is ( 0.00, -28.33)
Time is  0.30. ballBody is at ( 0.00, 10.75). It's velocity is ( 0.00, -30.00)
Time is  0.32. ballBody is at ( 0.00, 10.25). It's velocity is ( 0.00, -31.67)
Time is  0.33. ballBody is at ( 0.00,  9.72). It's velocity is ( 0.00, -33.33)
Time is  0.35. ballBody is at ( 0.00,  9.17). It's velocity is ( 0.00, -35.00)
Time is  0.37. ballBody is at ( 0.00,  8.58). It's velocity is ( 0.00, -36.67)
Time is  0.38. ballBody is at ( 0.00,  7.97). It's velocity is ( 0.00, -38.33)
Time is  0.40. ballBody is at ( 0.00,  7.33). It's velocity is ( 0.00, -40.00)
Time is  0.42. ballBody is at ( 0.00,  6.67). It's velocity is ( 0.00, -41.67)
Time is  0.43. ballBody is at ( 0.00,  5.97). It's velocity is ( 0.00, -43.33)
Time is  0.45. ballBody is at ( 0.00,  5.25). It's velocity is ( 0.00, -45.00)
Time is  0.47. ballBody is at ( 0.00,  4.50). It's velocity is ( 7.32, -1.83)
(here the program hangs indefinitely)

Hmm. It seems to stuck in recursion in cpSpaceProcessComponents(), but only using GCC 13? I poked at it for a while, but not quite sure what's going on yet.

I don't have a fix for this yet, and haven't had much time to work on it.

As a workaround you can do space->sleepTimeThreshold = INFINITY to disable object sleeping as a temporary workaround.

@slembcke Check the new pull request please.

I tried the workaround, but still get the freeze.
I can not directly access the members of space.
Instead I call cpSpaceSetSleepTimeThreshold(space, INFINITY).
Is there an update on this?

not sure about this but does this have a baring ?

                 from /home/chris/development/Chipmunk2D/src/cpBBTree.c:25:
/home/chris/development/Chipmunk2D/src/cpBBTree.c: In function 'partitionNodes':
/home/chris/development/Chipmunk2D/include/chipmunk/chipmunk.h:72:26: warning: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
   72 |         #define cpcalloc calloc
/home/chris/development/Chipmunk2D/src/cpBBTree.c:760:38: note: in expansion of macro 'cpcalloc'
  760 |         cpFloat *bounds = (cpFloat *)cpcalloc(count*2, sizeof(cpFloat));
      |                                      ^~~~~~~~
In file included from /home/chris/development/Chipmunk2D/src/cpBBTree.c:22:
/usr/include/stdlib.h:675:14: note: in a call to allocation function 'calloc' declared here
  675 | extern void *calloc (size_t __nmemb, size_t __size)
      |              ^~~~~~

by adding
set(CMAKE_C_COMPILER "clang")
to the cmake config (CMakeLists.txt) and re-running cmake I no longer see that error message (possibly related then??) and I no longer see this issue... GCC bug ??