physics crash - transition and removeSelf clash

hi,

please can you tell me why i get this simulator crash error? it seems to run file for a while, but in a specific instance I cannot determine the reason for it crashes. I can only assume that because removeSelf is not instant then 2 things are trying to act on it “at once”

thanks
j


Assertion failed: (0 <= proxyId && proxyId < m_nodeCapacity), function GetFatAABB, file …/…/external/Box2D_v2.1.2/Box2D/Box2D/Collision/b2DynamicTree.h, line 141.
/Applications/Corona Game Edition 2010.109/Corona Terminal: line 9: 1617 Abort trap “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*

[lua]local physics = require(“physics”)
local rnd = math.random

physics.start()

local line = display.newRect(0,300,170,20)
line:setFillColor(255,0,0)
line.is=“line”
physics.addBody(line, “static”, {density=1})

local function removeBall(obj,reason)
Runtime:removeEventListener(“enterFrame”, obj)

print(obj, reason)
if(obj~=nil) then
if(obj.transition~=nil) then transition.cancel(obj.transition) end
– *** occasionally crashes *** —
if(obj.removeSelf) then obj:removeSelf() end
end

return true
end
local function lineUp(event)
transition.to(line, {time=50, y=310})
end

local function globalCollision(event)

local obj1 = event.object1
local obj2 = event.object2

– if round ball hits line
if(obj2.is==“round” and obj1.is==“line”) then
transition.to(obj1, {time=100, y=obj1.y+10, onComplete=lineUp})
obj2.isBodyActive=false
obj2.transition = transition.to(obj2, {time=500, alpha=0, onComplete=function()removeBall(obj2,“hit line”)end})
return true
end
return true

end
local function newBall()

local ball

local radius = rnd(50)+5
local pick = math.floor(rnd(2))

if(pick==1) then

ball = display.newCircle(rnd(280)+20, 20, radius)
physics.addBody(ball, “dynamic”, {density=0.5, bounce=0.5,radius=radius})
ball.is=“round”

elseif(pick==2) then

ball = display.newRect(rnd(280)+20, 20,4,4)
physics.addBody(ball, “dynamic”, {density=1, bounce=0.1})
ball.is=“square”

end

ball:setFillColor(0,255,0)
ball.isBullet=true

– to be safe remove balls if they fall off the lower part of the screen
– otherwise they will continue falling forever
ball.enterFrame=function(self, event)
local ypos = self.y
if(ypos > 300) then self:setFillColor(255,0,0) end
if(ypos > 400) then removeBall(self,“y > 400”) end
end

Runtime:addEventListener(“enterFrame”, ball)

end
Runtime:addEventListener(“collision”, globalCollision)
timer.performWithDelay(100,newBall,-1)[/lua] [import]uid: 6645 topic_id: 4106 reply_id: 304106[/import]

it still happens if i remove the “lineUp” transition, so that part is not what’s causing the problem

[lua]transition.to(obj1, {time=100, y=obj1.y+10, onComplete=lineUp})[/lua]

it’s the other one

[lua]obj2.transition = transition.to(obj2, {time=500, alpha=0, onComplete=function()removeBall(obj2,“hit line”)end})[/lua]

clashing with

[lua]if(ypos > 400) then removeBall(self,“y > 400”) end[/lua]

however if i add this

[lua]print(“crash?”…obj.is)
if(obj.removeSelf) then obj:removeSelf() end[/lua]

the object just before the crash is “square” and that’s not one of the objects undergoing a transition

although the crash could be happening internally so not actually at that point (since removeSelf isnt instant anyway)
[import]uid: 6645 topic_id: 4106 reply_id: 12689[/import]

Hi jmp909,
Did you ever get this resolved? if so how?
I’m getting the same “assertion” error :frowning:

Hope you can help.

Thanks,
RD [import]uid: 7856 topic_id: 4106 reply_id: 18043[/import]

Hello,

jmp909 are you resolved the error ?

EDIT: Autoreply myself, I resolved the issue. The problem is when you set [lua]obj.isBodyActive = false[/lua] but the obj is still in moviment. To correct this, ensure the obj is stoped. I use:

[lua]obj:setLinearVelocity(0, 0)
obj.angularVelocity = 0
obj.isBodyActive = false[/lua]

I hope this help to all.

Regards.
Francisco. [import]uid: 11749 topic_id: 4106 reply_id: 24408[/import]

thanks hadn’t checked up on this for a while… will test it out

regards
j [import]uid: 6645 topic_id: 4106 reply_id: 24791[/import]

we also fixed series of removeself() bugs that caused a crash… the latest daily build drops has the fix.

c. [import]uid: 24 topic_id: 4106 reply_id: 24849[/import]