Please take a look at the following code. I create a rectangle (i.e. a button), put it inside a group and add a touch listener to it. Inside the touch listener I set the focus to the objects touched. Then I use a timer to remove the group within 3 seconds of being created.
If I am still pushing the “button” past the 3 seconds, when I then release I obtain that both the Corona simulator and the device crash. If I don’t set focus to the object touched OR I remove the button directly (and not its parent group) then no crash occurs.
Is this documented somewhere or have I hit a bug? What is actually going on in the event dispatch system? Is there some solution that does not require looping inside each layer of my display groups in order to remove a custom button/touch-sensitive-object?
Any indication welcome.
***
Run the following code in a main.lua on simulator, press the white button for above 3 seconds and then release. This should crash the simulator (and the device if you care to build).
\_W = display.contentWidth \_H = display.contentHeight local objectsB = display.newGroup() local button = display.newRect(\_W/2-100, \_H/2-100, 200, 200) objectsB:insert(button) -- \<== causing crash local function onTouch(event) self = event.target if event.phase == "began" or event.phase == "moved" then display.getCurrentStage():setFocus(self) -- \<== causing crash self:setFillColor(100,100,100) elseif event.phase == "ended" then self:setFillColor(255,255,255) display.getCurrentStage():setFocus(nil) -- \<== causing crash end return true end button:addEventListener("touch", onTouch) local function delay() display.remove(objectsB) -- \<== causing crash objectsB = nil -- causing crash end timer.performWithDelay(3000, delay)