Recieving segfault with collfunc

Official forum for the Chipmunk2D Physics Library.
Post Reply
vikkevest
Posts: 3
Joined: Fri Mar 21, 2008 7:58 am
Contact:

Recieving segfault with collfunc

Post by vikkevest »

Hello im not sure this is the place where im suppose to post this but otherwise you could point me in the right direction :roll: .

Currently im developing a small arcadegame as a schoolproject in pygame. I decided to use a physicsengine and discovered chipmunk. Im using these python bindings http://www.pyweek.org/d/932/ (not sure if theyre any good). Im absolutely not a pro in any way. So the problem is that segmentation faults show up when im using a collision function that detects collision between different physics items in the world. I have tried collision with different types of physic shapes. Now currently the collision function doesent do anything, and the segfault shows up event if it returns true or false. The segfault doesent show up on the first collision either, but comes after ive made a couple of balls that collide with the item.

To sum it all up: I get segfault after a random amout of collisions when using a collision function, and we assume that shapes that the collision function tracks collide.

I know its not a very technical report but im not sure what information im suppose to give sience i dont have a clue whats wrong. Chipmunk has been working very good and satisfying this far and I thank its developers :geek:
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Recieving segfault with collfunc

Post by viblo »

There has been quite some work on the wrapper since I made that post to pyweek. Pymunk now has its own homepage at http://pymunk.googlecode.com and you might also want to check out this thread in the community creations part of this forum: http://www.slembcke.net/forums/viewtopic.php?f=6&t=8 I suggest you upgrade :)

Anyway, it can be interesting to know the problem, I think it might be because you are not holding on to every object (probably the callback function reference) and when the GC runs it will collect some objects still used by chipmunk in the backgrund which causes the seg fault. This should not happen as easy if you use the new version, it will for example keep track of callback functions for you, but if it does crash please tell me as it might be a bug in pymunk or something which should be mentioned in the examples/docs/on the page.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
vikkevest
Posts: 3
Joined: Fri Mar 21, 2008 7:58 am
Contact:

Re: Recieving segfault with collfunc

Post by vikkevest »

Thanks for the reply ! :)
Now I have compiled the latest chipmunk version (im using linux) and managed to get it working with the latest pymunk. The good news then was that I didnt just get a boring message telling me that a segfault happened. But I got some info, the errormessage told me that one to much parameters were sent to the collfunc :| . I rechecked so that nothing was wrong with the parameters and still got the error. But I noticed on the new demos on pymunk that there apparently was some new changes (like when making a space you do space = Space() not cpSpaceNew()). But the old way worked also apparenly, I import chipmunk like this :
from pymunk._chipmunk import *

So I wondered I stuff work better if use chipmunk like in the pymunk demos?

Im not sure how I do when im not holding on to every object like you suggest, but ill try to look into it.
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Recieving segfault with collfunc

Post by viblo »

There are two layers in pymunk, the stuff in _chipmunk and then the other that you get when you just do a import of pymunk. The _chipmunk-layer is a lowlevel autogenerated (more or less) module which exports the basic "c"-chipmunk functions, structs and so on. Then there is the other layer made by hand, which are above _chipmunk and internaly uses it to speak with the chipmunk library file. I recommend you to use _chipmunk if there are features you need which is not available from the main pymunk module or you want to do some advanced operation (or just don't like the way the main pymunk module is structured :) ) and in other cases use the pymunk module which is the way the demos do as it is more high level and much more "pythonic" meaning it is easy to understand and use from python code.

For example, in the case of the collision callback, when you add a callback function using pymunk.Space.add_collisionpair_func() the code will add the function to an internal dictionary in the Space (so you don't have to keep track of it yourself, and don't get the seg fault) and wrap the function so when it is later called when a collision occurs it will be called with the passed in data, shapes of type pymunk.Shape and a python list of contacts instead of ctypes/chipmunk array with separate length variable.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
vikkevest
Posts: 3
Joined: Fri Mar 21, 2008 7:58 am
Contact:

Re: Recieving segfault with collfunc

Post by vikkevest »

Thanks for the help! Now with the new api I dont recieve the segfault, I dont think im going to use any particulary advanced options yet so it's good for now.
Post Reply

Who is online

Users browsing this forum: No registered users and 30 guests