pymunk icon indicating copy to clipboard operation
pymunk copied to clipboard

crash space add more then 40000 shapes

Open zipandrar opened this issue 5 years ago • 4 comments

this is a example source.py

crashTest.zip

#when the num is 30000 it work well #when the num is more than 40000 or 100000, it will get crashed in the line space.add(body, shape) #is it a bug or memeroy not enough??? but i think no one need more than 30000 bodies or shapes....

#i like pymunk.... ... in my test ,it is about 10x faster than pybox2d... ...

#faster and clear.... thanks to all of chipmunk's developers and thanks to all of pymunk's developers...

zipandrar avatar Jul 10 '19 18:07 zipandrar

Thanks for the report! Which version of pymunk, python and what OS do you use? I tried myself and got crashes on CPython 2.7 32 and 64bit and CPython 3.7 on Windows, but on CPython 2.7 64bits on Ubuntu I cant get it to crash.

viblo avatar Jul 10 '19 21:07 viblo

win7_64bit Cpython2.7.10_32bit pymunk_5.3.2

hmmm.so it is a memory problem.... it very very enough with 30000 shapes too....

zipandrar avatar Jul 11 '19 01:07 zipandrar

Lets keep this open a bit, just to keep track of it while I test a bit more. It seems to only happen for static and kinematic bodies, not dynamic ones. And the exception happens inside the chipmunk library code, in the cpArrayContains function.

viblo avatar Jul 11 '19 21:07 viblo

An update to this: I did some more investigation of this old ticket, and it turns out that nowadays its stack overflow in the spatial tree that causes error. I have reported it to the Chipmunk issue tracker, but given how slow that project moves nowadays I dont expect a fix soon.

There is a workaround, use the spatial hash instead (space.use_spatial_hash(...)). Using this I could not get it to crash as easily.

If you or someone else has a proper use case which this crash prevents I can take another look, otherwise I think I wont try too hard to make a fix..

viblo avatar Dec 21 '22 14:12 viblo