Reusing replaced scene

Reusing replaced scene
0.0 0


I have a CCScene which I originally used in a call to director runWithScene. Then, I use replaceScene to load a few new scenes. This works fine (from Lua of course).

At some point, I want to go back to my original (first) scene. When I do this, before I actually call replaceScene with it, I want to add some children to it by calling scene:addChild.

At this point, I get error:

invalid 'self' in function 'addChild'

This is the same code I ran for the original and subsequent scenes, it fails when I try to director.replace to any scene that was already used (original or subsequent).

Is it not allowed to reuse a scene? If not, what’s going on?


After more digging, it looks like although my object is still there (i.e. I still have the userdata), it’s somehow null.

So scenes cannot be reused after replaced? Can someone confirm or deny?


I think it maybe the reference of the object is 0,so the lua gc collect the object.Can you paste the codes made this error.


This was caused by:

  1. Show scene A from Lua
  2. Replace to scene B from Lua (but keep a reference to scene A
  3. Now try to replace back to scene A from Lua

This didn’t work for me, it looks like the C*+ scene was deleted out from under the Lua reference . So I can keep the Lua reference but I cannot reuse the C*+ underneath, it’s useless.

Can anyone confirm this is the case, or is it a bug?