JV-ODE Physics Wrapper

Blitz3D Forums/Blitz3D Userlibs/JV-ODE Physics Wrapper

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

i have create a sample code with this MAV Error....
restart it with SPACE Button and it crashing after reinitialize ode.

If you use the other Clear_ODE () method (see sample) with destroying bodys and geoms before destroy/close the ode , then crash the sample after many restarts...ca. > 3-20


test it!

i think, is a Bug in DLL. Leaks in communication with Destroying objects / close ode ?

only solution short-term: Initializing ode only once and destroy only Types,bodys and geoms. It Works without Problems...but a fault in this nevertheless is.

With My Method , ode runs very stably without closing ode and new initialization. I Destroy then only the bodys and geoms and creating new Objects. Works fine, without problems. whether this remains so?
50x Reloading the Level and no problems.
Here the Working ODE_CLEAR () Function:

Function ODE_CLEAR ()
For ode.ODEGeom=Each ODEGeom
dBodyDestroy(ODE\body)
dGeomDestroy(ODE\geom)
Delete ode
Next
End Function


AppTitle "JV-ODE - Cubes Demo"

Include "ode.bb"



Type ODEGeom
	Field body
	Field geom
	Field mesh
End Type

; ###################################################################################################

; ### Setup ODE

Global World
Global Space
Global ContactGroup

Global Light
Global Camera



;=============================================
.RESTART


Graphics3D 1280,1024,32,2; 800,600,0,2

INIT_ODE ()

Light=CreateLight()
RotateEntity Light,45,-90,0
LightColor Light,255,255,255
AmbientLight 130,130,130

Camera=CreateCamera()
CameraClsColor Camera,0,0,0
CameraRange Camera,1,1000
PositionEntity Camera,0,20,-50
RotateEntity Camera,30,0,0

dCreatePlane(Space,0,1,0,0)
Plane=CreatePlane()
EntityAlpha Plane,0.8
ClsColor 0,0,0
Cls


; ###################################################################################################
Close=0
Cls
FlushKeys

While Close=0

	PTime=MilliSecs()

	If MilliSecs()-Timer>100
		AddObject()
		Timer=MilliSecs()
		End If

	UPDATE_ODE ()

	PhysicsTime#=MilliSecs()-PTime

	UpdateWorld
	RenderWorld

	Text 0,30,"PRESSS SPACE TO RESTART  or  ESC to Quit"

	Flip

	If KeyHit (1) Then Close=1
	If KeyHit (57) Then Close=2
Wend


CLEAR_ODE ()
ClearWorld 1,1,1 

If Close=2 Then
  Goto RESTART
EndIf
End








Function INIT_ODE ()
World=dWorldCreate()
Space=dHashSpaceCreate(0)
ContactGroup=dJointGroupCreate(0)
dWorldSetAutoDisableFlag(World,0)
dWorldSetGravity(World,0,-5,0)
dContactSetMode(dContactBounce)
dContactSetBounce(0.1)
dContactSetMu(48)
dCreatePlane(Space,0,1,0,0)
End Function

;---------------------------------------------------
; ODE Crashing after restarting it 2x
;---------------------------------------------------

Function CLEAR_ODE ()
 dJointGroupDestroy(ContactGroup)
 dSpaceDestroy(Space)
 dWorldDestroy(World)
 dCloseODE()
 For ode.ODEGeom=Each ODEGeom
  Delete ode
 Next
End Function


;-------------------------------------------------------
;Other Clear Method > ODE CRASHING AFTER RESTARTING IT > 3 - 30 (many restarts) 
;-------------------------------------------------------

;Function CLEAR_ODE ()
; For ode.ODEGeom=Each ODEGeom
;  dbodyDestroy(ode\body)
;  dgeomDestroy(ode\geom)
;  Delete ode
; Next
; dJointGroupDestroy(ContactGroup)
; dSpaceDestroy(Space)
; dWorldDestroy(World)
; dCloseODE()
;End Function


Function UPDATE_ODE ()
 UpdateGeoms()
 dSpaceCollide(Space,World,ContactGroup) ;>>>> MAV ERROR LINE 
 dWorldQuickStep(World,0.1)
 dJointGroupEmpty(ContactGroup)
End Function
; ###################################################################################################

Function AddObject()

xp=Rand(-10,10)
zp=Rand(-10,10)
ode.ODEGeom=New ODEGeom
ode\body=dBodyCreate(World)
dBodySetRotation(ode\body,0,0,0)
dBodySetPosition(ode\body,xp,30,zp)
dBodySetAutoDisableFlag(ode\body,1)
ode\geom=dCreateBox(Space,5,5,5)
dGeomSetBody(ode\geom,ode\body)
ode\mesh=CreateCube()
ScaleMesh ode\mesh,2.5,2.5,2.5
EntityColor ode\mesh,Rand(255),Rand(255),Rand(255)
EntityAlpha ode\mesh,1
EntityShininess ode\mesh,0.7

End Function

; ###################################################################################################

Function UpdateGeoms()

For ode.ODEGeom=Each ODEGeom
	If dBodyIsEnabled(ode\body)
		RotateEntity ode\mesh,dGeomGetPitch#(ode\geom),dGeomGetYaw#(ode\geom),dGeomGetRoll#(ode\geom)
		PositionEntity ode\mesh,dGeomGetPositionX#(ode\geom),dGeomGetPositionY#(ode\geom),dGeomGetPositionZ#(ode\geom)
		End If
Next

End Function

; ###################################################################################################