Games using the Chipmunk4PB wrapper (2D physic engine)

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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)
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post by gnasen »

try this order:

Code: Select all

cpSpaceRemoveShape()
cpShapeFree()
cpSpaceRemoveBody()
cpBodyFree()
pb 5.11
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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?
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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.
pb 5.11
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post by AndyLy »

Need Chipmunk4PB_v0.4.pbi, my dll and resources.
https://rapidshare.com/files/827199597/My_project_3.pb
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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.
pb 5.11
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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.
pb 5.11
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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.
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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.
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post by gnasen »

Nice, as I see you learn fast ;) no problem, if I have time I will try to help you, just ask.
pb 5.11
User avatar
IceSoft
Addict
Addict
Posts: 1698
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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?
pb 5.11
User avatar
AndyLy
Enthusiast
Enthusiast
Posts: 228
Joined: Tue Jan 04, 2011 11:50 am
Location: GRI

Re: Who is also working on a Chipmunk wrapper (2D physic eng

Post 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.
'Happiness for everybody, free, and no one will go away unsatisfied!'
SMsF town: http://www.youtube.com/watch?v=g6RRKYf_Pd0
SMf locations module (Ogre). Game video: http://www.youtube.com/watch?v=ZlhBgPJhAxI
Post Reply