Page 3 of 6
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 1:53 pm
by AndyLy
The error occurs here:
Code: Select all
ProcedureC col_begin2(*arb.cpArbiter, *space.cpSpace, *pData)
Protected *bodyA.cpbody = *arb\private_a\body
Protected *bodyB.cpbody = *arb\private_b\body
tmpvar=(Abs(*bodyB\v\x)+Abs(*bodyB\v\y))
If tmpvar>BrickDestrucKf: cpSpaceRemoveBody(*space, *bodyB): cpBodyFree(*bodyB)
cpSpaceRemoveShape(*space, *shapeB): cpShapeFree(*shapeB): EndIf
ProcedureReturn #True
EndProcedure
While I can not understand why, it occurs in a random manner.
And when you exit the program if all the glass bricks are broken - crash here.
Code: Select all
cpSpaceFree(*space): cpBodyFree(*staticBody)
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 3:39 pm
by gnasen
try this order:
Code: Select all
cpSpaceRemoveShape()
cpShapeFree()
cpSpaceRemoveBody()
cpBodyFree()
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 5:25 pm
by AndyLy
Still crashes on exit, in a random manner. On line : cpSpaceFree (*space)
Something wrong with the removal of objects. The longer you play - the more likely the crash.
to gnasen : And how are you delete them?
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 7:36 pm
by gnasen
AndyLy wrote:Still crashes on exit, in a random manner. On line : cpSpaceFree (*space)
Something wrong with the removal of objects. The longer you play - the more likely the crash.
to gnasen : And how are you delete them?
Without any code I can just guess. If you use a list with the objects, be sure that you delete the element connected with the body and shapes from the list itself.
If you could post a working example, I could have a look at it.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 7:53 pm
by AndyLy
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 8:04 pm
by gnasen
AndyLy wrote:...Need Chipmunk4PB_v0.4.pbi, my dll and resources...
yes, and I need them, too

I can only try to debug runable code. Otherwise its just hell.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 8:12 pm
by AndyLy
Dll and resources you already have (you downloaded the previous example).
Нere Chipmunk4PB_v0.4.pbi :
https://rapidshare.com/files/1077635616 ... B_v0.4.rar
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 8:31 pm
by gnasen
ah okay, now I see the problem.
You delete the body/shape, while you are in the callback. So you are removing it while chipmunk is still working with it. So if your callback is left and chipmunk tries to access the body/shape, it gets an invalid memory access.
you have to use Post-Step Callbacks, just see in the manual.
Honestly I dont use it, because I just gather all information in the callback and store it to a collision list. After chipmunk has done its timestep, I handle all collisions and can delete/add/modify whatever I want.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 8:50 pm
by AndyLy
I tried to copy the objects into a single list and remove them after cpSpaceStep (* space, dt), but there was crash program.
I've done this:
Structure object: body.cpbody: shape.cpshape: mydata.i: EndStructure: Global NewList obj.object ()
.........
; In ProcedureC col_begin ()
CopyStructure (* bodyB, obj (), cpbody)
......................
; After cpSpaceStep ()
ForEach obj (): cpSpaceRemoveBody (* space, obj () \ body): next
use Post-Step Callbacks, just see in the manual
Yes I watched the manual but it is in C, I did not understand.
Can give an example for PureBasic, working with the Post-Step Callbacks? I would appreciate it.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sun Aug 21, 2011 12:43 am
by AndyLy
In general, a couple of cups of coffee and some cigarettes, and I was able to write PostStep () handling to remove blocks.
At the moment everything is working. I will try other options. Thanks again for your help.
Hopefully in the future, you do not refuse to advice if necessary.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sun Aug 21, 2011 11:43 am
by gnasen
Nice, as I see you learn fast

no problem, if I have time I will try to help you, just ask.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sun Aug 21, 2011 12:02 pm
by IceSoft
gnasen wrote:Nice, as I see you learn fast

no problem, if I have time I will try to help you, just ask.
Thanks for your help by me too.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sun Aug 21, 2011 10:43 pm
by AndyLy
Nothing really new, just corrected the bugs and added a goal to drop the large board with the right edge, with a single shot.
Right mouse button, increase the strength of the shot. Left-fire.
https://rapidshare.com/files/109141931/examp.rar
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Mon Aug 22, 2011 12:00 am
by gnasen
Well done, I think youve already created more complicated things then I ever did in chipmunks!
I guess you want to create a "trebuchet vs fort" game?
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Mon Aug 22, 2011 12:09 am
by AndyLy
Well done, I think youve already created more complicated things then I ever did in chipmunks!
What can I say, I'm a genius.
I guess you want to create a "trebuchet vs fort" game?
I do not know what it is.
While the idea of the game is in the air. I do not know yet, realizing something playable or not.