Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Destroying a physics object in collide function crashes Codea

IgnatzIgnatz Mod
edited April 2013 in Bugs Posts: 5,396

It seems that if you destroy a physics object in the collide function (when it is one of the colliding bodies), Codea crashes or hangs, as shown by the code below. Turn the Crash parameter on to see the behaviour.

If this is intended, can we put a warning in the documentation somewhere?


function setup() physics.gravity(0,0) parameter.boolean("Crash",false) circle1= physics.body(CIRCLE, 50) circle1.x,circle1.y=100,400 circle1.type=DYNAMIC circle1.linearVelocity=vec2(80,0) circle2=physics.body(CIRCLE,50) circle2.x,circle2.y=600,400 circle2.linearVelocity=vec2(-50,0) circle2.type=DYNAMIC print("I want to delete the left hand circle when they collide") print("With Crash turned OFF, circle is destroyed in draw function") print("With Crash turned ON, circle is destroyed in collide function") end function draw() background(200) fill(0,0,255,100) ellipseMode(CENTER) if destroy then circle1:destroy() circle1=nil destroy=nil end if circle1 then ellipse(circle1.x,circle1.y,100) end ellipse(circle2.x,circle2.y,100) end function collide(contact) if Crash then --destroy circle here circle1:destroy() circle1=nil else destroy=true --tell draw to destroy circle end end

Comments

Sign In or Register to comment.