sdkluacoronasdklime

Corona "Attempt to remove an object that has already been removed"


I'm working on a simple "breakout" game and I have problem reloading a map. for example: if I start with level1, break some bricks and lose, than I'm loading the same map again. next time that the ball collides with the same brick I "touched" before, will give me an error Attempt to remove an object that has already been removed

local map = lime.loadMap("maps/" .. currentLevel .. ".tmx")
local layer = map:getTileLayer("bricks_1")
local visual = lime.createVisual(map)
local physical = lime.buildPhysical(map)


function removeBricks(event)
    if event.other.isBrick then
        local brick = event.other
        transition.to(brick, {time = 20, alpha = 0})

        score = score + brick.scoreValue
        ScoreNum.text = score 

        -- remove brick
        brick:removeSelf()
        brick = nil
        ...

Solution

  • i think the second time you go to your game the event.other is not created are you using storyboard if so you can try to remove the scene after the game is over so when you go to your game again it will recreate all the object