pymunk icon indicating copy to clipboard operation
pymunk copied to clipboard

Segmentation fault when setting `body_type` to dynamic

Open aatle opened this issue 1 year ago • 1 comments

Setting a body's body_type to Body.DYNAMIC causes a Segmentation fault (core dumped) under the following conditions:

  • A SlideJoint is attached to the body. Other types of joints don't seem to have a problem.
  • Pymunk version >=6.7.0 .
  • The body type was not already dynamic to begin with.
import pymunk as pm

print('pymunk version', pm.version)
print('chipmunk version', pm.chipmunk_version)
space = pm.Space()

body = pm.Body(body_type=pm.Body.KINEMATIC)
space.add(body)

# this body type doesn't matter
other = pm.Body(body_type=pm.Body.KINEMATIC)
joint = pm.SlideJoint(body, other, (10,0), (20,0), 5, 5)
# joint = pm.PinJoint(body, other)
space.add(other, joint)

for i in range(20):
  print('step START', i)
  space.step(1/60)
  print('step END', i)
  if i == 10:
    print('setting DYNAMIC')
    body.body_type = pm.Body.DYNAMIC  # Segmentation fault
    print('DONE')
print('FINISHED')

Tested on windows and ubuntu. Might be a problem in chipmunk and not pymunk.

Note: I originally found this bug when trying to recalculate the moment for a dynamic body, as I had overwritten it previously and the only easy ways to do it seemed to be to store the original or reset the body type.

aatle avatar Jun 25 '24 20:06 aatle

Thanks for the report!

I'm almost sure its in Chipmunk. Not that long ago I made it possible to change the body type and have a constraint connected at the same time, but looks like I missed something. Probably it's not too difficult to fix.

I'm on a long trip abroad right now, but will take a look once I'm back.

On Wed, Jun 26, 2024, 04:52 aatle @.***> wrote:

Setting a body's body_type to Body.DYNAMIC causes a Segmentation fault (core dumped) under the following conditions:

  • A SlideJoint is attached to the body. Other types of joints don't seem to have a problem.
  • Pymunk version >=6.7.0 .
  • The body type was not already dynamic to begin with.

import pymunk as pm print('pymunk version', pm.version)print('chipmunk version', pm.chipmunk_version)space = pm.Space() body = pm.Body(body_type=pm.Body.KINEMATIC)space.add(body)

this body type doesn't matterother = pm.Body(body_type=pm.Body.KINEMATIC)joint = pm.SlideJoint(body, other, (10,0), (20,0), 5, 5)# joint = pm.PinJoint(body, other)space.add(other, joint)

for i in range(20): print('step START', i) space.step(1/60) print('step END', i) if i == 10: print('setting DYNAMIC') body.body_type = pm.Body.DYNAMIC # Segmentation fault print('DONE')print('FINISHED')

Tested on windows and ubuntu. Might be a problem in chipmunk and not pymunk.

Note: I originally found this bug when trying to recalculate the moment for a dynamic body, as I had overwritten it previously and the only easy ways to do it seemed to be to store the original or reset the body type.

— Reply to this email directly, view it on GitHub https://github.com/viblo/pymunk/issues/250, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJD2CFIOP3BRWWQLHY75ETZJHKB5AVCNFSM6AAAAABJ4SX2GKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3TGNRTHA4TAMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

viblo avatar Jun 27 '24 08:06 viblo