Gizmo Manager dispose issue on reactjs

Hi, I am trying to dispose gizmo manager in react(CRA) but it gives me this weird error

TypeError: Cannot read property ‘dispose’ of undefined

My babylon version:

"babylonjs": "^5.0.0-alpha.25",
"babylonjs-loaders": "^5.0.0-alpha.25",
"babylonjs-materials": "^5.0.0-alpha.25",

This is how I am defining the gizmo manager:

    gizmoManager: new GizmoManager(scene, 1, new UtilityLayerRenderer(scene)),

and this is how I am disposing it(on a button click):


During debugging if I stop the execution a line before dispose I can see that this.state.gizmoManager is not undefined and it contains the GimoManager Object.

Console log of the error

Also I created another project using


and I get this error from it:

@Cedric I think you are the go to guy for anything related gizmos. Can you please take a look at this issue.

Hey Hamid Nawaz,
You are getting the above error because the state hasn’t been assigned yet. This explains as why you are getting → dispose() is not a function. You might wanna try the following:

   this.setState({ gizmoManager: new GizmoManager(scene) }, () => {
1 Like

This crash should be fixed by this PR : fix crash in sixDofDragBehavior.ts by CedricGuillemet · Pull Request #10515 · BabylonJS/Babylon.js · GitHub
Which is in latest nightly. Let me know how it goes.

1 Like

Thank you. Its working perfectly now.