_sceneRootNodesIndex' error

Hey everyone,
I recently updated babylonjs from 4.0.0-alpha8 to 4.0.3
I have a 2 scene style game when you can go back and forth between the two. Now when i go between the two i get this error “Cannot set property ‘_sceneRootNodesIndex’ of undefined”
It could be that my logic for cleaning up the old scene is slightly off, but im wondering if something im not seeing could be causing this. This seemed to work fine in the alpha build i was using.

I get this when i try to console log scene.rootNodes right before the error

  1. (52) [t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, Character, t, t, t, t]
  2. 0: t {state: “”, metadata: null, reservedDataStore: null, doNotSerialize: false, _isDisposed: true, …}
  3. 4: undefined
  4. length: 5
  5. proto: Array(0)

Any ideas?

Hey, this is complicated to help you with so few information :frowning:
Can you repro in the playground ?

1 Like

Im trying to but im having troubles,
https://www.babylonjs-playground.com/#KNPDAR
https://www.babylonjs-playground.com/#PLTRBV

There seems to be a problem with trying to use advance dynamic texture on the stable version of playgound

Ok let me fix that first :slight_smile:

1 Like

ok i think you fixed the playground at some point…
Thanks :slight_smile:

I have not been able to reproduce the bug :confused:

Here is as close as i could get, to what i do in my scene.
https://www.babylonjs-playground.com/#KYVA24
So i went back to mine, and started debugging again. This bug seems to only happen when i dispose of my main game scene. Even if i dont switch scenes. So im really confused at what could be happening. Since i stop rendering the scene then i try disposing the scene, but get that error.

“Cannot set property ‘_sceneRootNodesIndex’ of undefined”

So far my only hunches are that it could be something to do with using assets loaded from another scene. Like in this post:

any ideas on how i should go about diagnosing what the problem could be?

Ive console logged all the way and end up getting the error on the scene.dispose(), but that works in the playground. So maybe its something im doing to my scene before i dispose? Im not sure… Back to debugging :smiley:

full error:


babylon.js:16 Uncaught (in promise) TypeError: Cannot set property ‘_sceneRootNodesIndex’ of undefined
at t.e.removeFromSceneRootNodes (babylon.js:16)
at t.e.dispose (babylon.js:16)
at t.dispose (babylon.js:16)
at t.dispose (babylon.js:16)
at PlayScene.destroy (PlayScene.ts:740)
at PlayScene.leaveGameScene (PlayScene.ts:732)
at eventDispatcher.ts:66
at Array.forEach ()
at EventDispatcher.dispatch (eventDispatcher.ts:65)
at Container. (container.ts:94)
at step (gameadapter.js:31)
at Object.next (gameadapter.js:12)
at gameadapter.js:6
at new Promise ()
at __awaiter (gameadapter.js:2)
at Object.onRestart (container.ts:89)
at GameOverComponent. (gameOverComponent.ts:63)
at step (gameadapter.js:31)
at Object.next (gameadapter.js:12)
at gameadapter.js:6
at new Promise ()
at __awaiter (gameadapter.js:2)
at Object.onRestart (gameOverComponent.ts:61)
at HTMLDivElement. (actionsComponent.ts:35)


hopefully this help

If I put:


this.scene.rootNodes.forEach(node => node.dispose());


Before the this.scene.dispose it fixes it for most cases, but not all.

With the remaining cases being scene with some extra objects, that dont seem to have much different than the others.

Ok, so it seems like mesh._scene is hidden now. I think that could be the problem…
or something with the cloning
https://www.babylonjs-playground.com/#KYVA24#1

is there another way to change the scene of a mesh?

Woot! You cannot change the scene of a mesh. There will be thousands of problems if you do that :slight_smile:
That is mostly why we introduced the asset container so you can have groups of active/inactive meshes inside a scene:
https://doc.babylonjs.com/how_to/how_to_use_assetcontainer

As a rule of thumb, you should never use anything starting with _

1 Like

i know i shouldnt use anything with _ but theyre so powerful !

So theres no way i can load a mesh in one scene and then use it in another?

Otherwise im going to need to load meshes everytime i re create one of my scenes, if i understand correctly.

although they would be cached already

You should not change scene actually if you share meshes. From a memory/performance standpoint, it is better to use asset containers

1 Like

Im not sure i fully understand.

You should not change scene actually if you share meshes.

Do you mean i should only use one scene, then use assets containters as “scene” with all my assets in them ? Then use the asset container to add in a whole “scene” and remove a whole “scene”. Like just adding in whole sets(“scenes”) of meshes and other assets?
Or just dont switch the scene of a mesh?

Use the assetContainer to load the file then just call the file from the asset container when i need it?
but assetContainer needs a scene, so that doesnt seem right…

I dont understand the purpose of assetContainers

Correct!

AssetContainer can be loaded from file and they live in the scene. They can then be added to the scene or remove from the scene