attempt to call method 'removeSelf' (a nil value) help?

At one level, the issue with objects not being able to removeSelf is usually caused by the object already having been removed from the display somehow.

One sure fire way to avoid the error is to test for the presence of removeSelf() as a method *before* calling it. This can be done as so

[lua]

    if( rect.removeSelf ~= nil ) then    – Make sure it is still in the display hierarchy

        rect:removeSelf()

    end

[/lua]

However, this does not solve any fundamental issues code may have with symmetrical loading / releasing of assets. It’s just a method to check that objects actually are in the display hierarchy before deleting them. (The removeSelf method is added to the object when inserted into the display, and the mthod is removed when the object is removed from the display).

Don’t think I’ve every seen this trick posted in the forums, hopefully a corona staffer won’t jump in here and blast me out of the water on this technique… But it seems to work as a last ditch stopgap.

Thanks I’ll try that soon and get back to you, the only fix I can work out is just to embed the game code at the main.lua level then it never reloads just art assets, but eventually I’ve found that using :translate or .x on a sprite begins to break down in the same manner.

It’s a really frustrating bug that seems to have nothing with my code causing it.

Your case sounds tougher obscure.

As a general practice, whenever I create an object in code, I write (at the same time) the code/function to remove it. By doing it at the same time (literally), I’m (forced to be) aware of any/all the special circumstances that might happen to the object between the time it is created and destroyed.

If you’ve just been creating objects left and right, and inserting/removing them arbitrarily - then it could be difficult to track down the sources of your errors.

In your example just above, you didn’t show how the group was created. As is, that code should work. However, you say it doesn’t so we must assume there’s more to it than that. My guess would be (in that particular case) that group cannot insert the object because group itself was somehow removed from the display (if it’s parent was removed, that counts too).

I have this same bug all over the place, with insert apparently being nil and remove and removeSelf

It’s painful as hell, does anyone have a fix for this yet?

tried asserting whether the table or the object with insert and remove were nil already and they weren’t. Also this is an error which only occurs on the second time I load a scene, the first time runs without hitches, but I really dont see how anything could cause those functions to nil themselves, I certainly don’t do it anywhere.

Heres an example of one of the errors

attempt to call method 'insert' (a nil value)

local rect = display.newRect(0,0,game.screen.width,game.screen.height) rect:setFillColor(100, 100, 100, 150) group:insert(rect)

Any help would be vastly appreciated since this is to a deadline and this bug has been re-occuring throughout wherever I reload a scene

At one level, the issue with objects not being able to removeSelf is usually caused by the object already having been removed from the display somehow.

One sure fire way to avoid the error is to test for the presence of removeSelf() as a method *before* calling it. This can be done as so

[lua]

    if( rect.removeSelf ~= nil ) then    – Make sure it is still in the display hierarchy

        rect:removeSelf()

    end

[/lua]

However, this does not solve any fundamental issues code may have with symmetrical loading / releasing of assets. It’s just a method to check that objects actually are in the display hierarchy before deleting them. (The removeSelf method is added to the object when inserted into the display, and the mthod is removed when the object is removed from the display).

Don’t think I’ve every seen this trick posted in the forums, hopefully a corona staffer won’t jump in here and blast me out of the water on this technique… But it seems to work as a last ditch stopgap.

Thanks I’ll try that soon and get back to you, the only fix I can work out is just to embed the game code at the main.lua level then it never reloads just art assets, but eventually I’ve found that using :translate or .x on a sprite begins to break down in the same manner.

It’s a really frustrating bug that seems to have nothing with my code causing it.

Your case sounds tougher obscure.

As a general practice, whenever I create an object in code, I write (at the same time) the code/function to remove it. By doing it at the same time (literally), I’m (forced to be) aware of any/all the special circumstances that might happen to the object between the time it is created and destroyed.

If you’ve just been creating objects left and right, and inserting/removing them arbitrarily - then it could be difficult to track down the sources of your errors.

In your example just above, you didn’t show how the group was created. As is, that code should work. However, you say it doesn’t so we must assume there’s more to it than that. My guess would be (in that particular case) that group cannot insert the object because group itself was somehow removed from the display (if it’s parent was removed, that counts too).