Group.dispose() is not a function

I have been working with groups and trying to dispose of them is resulting in a not a function error (maze3d.js 1466. This error does not happen when working with instances

The live demo can be found here: Interactive maze3d 3.0.0 - CodeSandbox

Under the model settings drop down, uncheck the instance checkbox and it will cause the error.

Basically, the object on the screen is made up of instance meshes. When you uncheck the box, it will use a group of individual Box Geometries instead.

The function that makes these groups is called generateModel on line 635 of maze3d.js

Its a large project, and I don’t expect anyone to comb through my code. However, I am trying to understand how a basic three.js group may not have the ability to dispose.

The scene is passed from world.js to mazed3d.js in order to add the groups to the scene in the modelAPI function.

group and object3d do not have dispose, easy as that. you’ll find it on meshes, lines, etc.

obj.traverse(obj => obj.dispose?.())
1 Like

I’m afraid that’s not right. The only 3D objects with a dispose() method are InstancedMesh (because of its internal instanced attributes) and certain helpers (because of their internal geometries/materials).

Just creating a group does not allocated disposable resources. The relevant entities are mostly materials, geometries and textures. Since they can be reused across 3D objects, you have to maintain their lifecycle by yourself (and thus call dispose() when appropriate).

1 Like

Thank you and @drcmda for the information.

Do I even need to dispose of the Box Geometries inside of the group in my example? I can say that, due to the program structure, it will only ever contain Meshes with a Box Geometry or a similar basic Geometry. Light and shadow helpers are delt with in separate functions, do I need to dispose of them too?

Is their a list online of all classes that require dispose and those that do not?

https://threejs.org/docs/index.html?q=dispose#manual/en/introduction/How-to-dispose-of-objects

1 Like

Does disposing of a mesh also dispose its material and geometry?

There is no way to call dispose() on a mesh. You can only remove it from the scene. dispose() has to be called for its geometry and material if appropriate.

1 Like