Corona Simulator Crashes when i call a remove self function

I don’t know where to report this so here it is.

here is the basic code that made it crash.  Corona just exits, no error message or anything.  Im reporting because i think the simulator should at least give an error message in cause you didn’t know what you did wrong.  I managed to do this while experimenting around, and this code probably wouldn’t ever be used for real.

[lua]

local function onred1Event( event )

    

    if event.phase == “began” then

    

        score = score+10

        score1.text = score

    

    elseif event.phase == “moved” then

        

            print(“lose”)

    

            score = score-10

            score1.text = score

    

            event.target:removeSelf() --THIS CAUSES THE CRASH

    

        end

    

    elseif event.phase == “ended” or event.phase == “cancelled” then

    

        score = score-10

        score1.text = score

    

    end

    

    temp:store( “score”, score )

    temp:save()

    

    return true    – indicates successful touch

end

[/lua]

the display object this function is triggered by gets removed and then corona crashes.  I marked the line i believe caused the crash.  Just thought the devs should know.

PS- if anyone knows how to manually cancel the event where i have the crash line, that would be great too :slight_smile: .

devs let me know if you need more info

You can put the remove in a timer to give the the event handler a place to return to.

but why would the simulator crash, shouldn’t it just give me an error…

and can i do just event:removeSelf() in a timer?  I want my display object to still be there.

I’ll pass this on to the engineers.  I think we would like for things to not crash.

have you tried

display.remove(event.target)

instead of removeSelf

i don’t want to remove the target, just the event (if that is possible)  I think that is why it crashed is cause i removed the target.  I want to cancel the event so this code runs:

[lua]

  1. elseif event.phase == “ended” or event.phase == “cancelled” then
  2.     
  3.         score = score-10
  4.         score1.text = score
  5.     [/lua]

removeEventListener

I’ll check but I believe this is fixed in Daily Builds and will be in the next Release Build:

Core: Fix issue with focus on child objects which could cause a crash - fixes casenum 21818, 23684

The issue stems from the deleted object still having “focus” (in some sense) and the Simulator crashing when it tries to return focus to the deleted object.  Most people don’t see the bug but those that do see it a lot, sorry.

ok, thanks

You can put the remove in a timer to give the the event handler a place to return to.

but why would the simulator crash, shouldn’t it just give me an error…

and can i do just event:removeSelf() in a timer?  I want my display object to still be there.

I’ll pass this on to the engineers.  I think we would like for things to not crash.

have you tried

display.remove(event.target)

instead of removeSelf

i don’t want to remove the target, just the event (if that is possible)  I think that is why it crashed is cause i removed the target.  I want to cancel the event so this code runs:

[lua]

  1. elseif event.phase == “ended” or event.phase == “cancelled” then
  2.     
  3.         score = score-10
  4.         score1.text = score
  5.     [/lua]

removeEventListener

I’ll check but I believe this is fixed in Daily Builds and will be in the next Release Build:

Core: Fix issue with focus on child objects which could cause a crash - fixes casenum 21818, 23684

The issue stems from the deleted object still having “focus” (in some sense) and the Simulator crashing when it tries to return focus to the deleted object.  Most people don’t see the bug but those that do see it a lot, sorry.

ok, thanks