brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
821 stars 105 forks source link

advancedDynamicTextureMaterial keeps dangling even when the component is unmounted #290

Closed jinincarnate closed 1 year ago

jinincarnate commented 1 year ago

Hi I have created a 3d UI in VR using a similar code as shown in the link below

https://brianzinn.github.io/react-babylonjs/examples/gui/2d-gui

but when the component is unmounted all objects like plane, advancedDynamicTexture, and all other ui components gets destroyed, but advancedDynamicTextureMaterial (that gets created automatically) doesn't get disposed and keeps hanging in the scene. Is there a way to get its reference so that it can be disposed.

brianzinn commented 1 year ago

do you know the imperative solution? if you can make a regular babylon PG then I'm sure we can figure it out.

jinincarnate commented 1 year ago

Hi i have tried adding babylonjs inspector to your example so that the issue can be seen easily. the code might run a lil slow just tried to cook up something fast.

Try it on https://codesandbox.io/s/relaxed-solomon-75zjci

image

as u can see in the image multiple instances of advanced dynamic texture material are getting created as we open and close the 3d UI

brianzinn commented 1 year ago

thanks @jinincarnate - I found the memory leak. the sandbox was a great repo.

brianzinn commented 1 year ago

@jinincarnate can you confirm it's fixed in 3.1.17?

jinincarnate commented 1 year ago

looks like solved