Error leads to unexpected quitting of the simulator

Hi,

I just started programming with the Corona SDK and made a simple program for testing purpose:

[blockcode]
physics=require(“physics”)
display.setStatusBar(display.HiddenStatusBar)

function createGame()
physics.start()
physics.setGravity(0,0)
createPlayer()
createBounds()
end

function deleteGame()
deleteBounds()
deletePlayer()
physics.stop()
end

function createPlayer()
player=display.newRect(0,0,40,40)
physics.addBody(player,{isSensor=true})
player.x=display.contentWidth*0.5
player.y=display.contentWidth*0.5

local function onTouch(event)
player.x=event.x
player.y=event.y
end

Runtime:addEventListener(“touch”,onTouch)
Runtime.touch=onTouch
end

function deletePlayer()
player:removeSelf()
player=nil
Runtime:removeEventListener(“touch”,Runtime.touch)
end

function createBounds()
bounds={}

bounds[1]=display.newRect(0,0,display.contentWidth,20)
physics.addBody(bounds[1],{isSensor=true})
bounds[1]:setFillColor(255,255,255)

bounds[2]=display.newRect(0,display.contentHeight-20,display.contentWidth,display.contentHeight)
physics.addBody(bounds[2],{isSensor=true})
bounds[2]:setFillColor(255,255,255)

bounds[3]=display.newRect(0,0,20,display.contentHeight)
physics.addBody(bounds[3],{isSensor=true})
bounds[3]:setFillColor(255,255,255)

bounds[4]=display.newRect(display.contentWidth-20,0,display.contentWidth,display.contentHeight)
physics.addBody(bounds[4],{isSensor=true})
bounds[4]:setFillColor(255,255,255)

local function onCollision(self,event)
if event.other==player then
deleteGame()
createGame()
end
end

for i,v in pairs(bounds) do
bounds[i].collision=onCollision
bounds[i]:addEventListener(“collision”,bounds[i])
end
end

function deleteBounds()
for i,v in pairs(bounds) do
bounds[i]:removeSelf()
bounds[i]=nil
end
bounds=nil
end

createGame()
[/blockcode]

It runs well, but if I hit the bounds, so that the game restarts, the simulator quits with an unexpected error.
The strange thing about it is that sometimes I can hit the bounds for two or three times and I get no error.

I’d be very grateful if someone could give me a hint. [import]uid: 13389 topic_id: 4767 reply_id: 304767[/import]

I’ve looked at the code again and maybe found my mistake:
Could it be possible that you can’t destroy an object, while your in a method of this object?
[import]uid: 13389 topic_id: 4767 reply_id: 15286[/import]