Skip to content

Commit c845d3f

Browse files
committed
Dispose of any mesh, instead of current mesh -- allows for dynamically switching mesh type
With this change you can now change in-game (e.g. with voxel-debug): game.meshType = 'surfaceMesh' game.meshType = 'wireMesh' and explore new chunks, then the old meshes will be properly cleaned up (vs crashing).
1 parent 47a05ba commit c845d3f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,14 @@ Game.prototype.removeFarChunks = function(playerPosition) {
486486
if (!chunk) return
487487
var chunkPosition = chunk.position
488488
if (mesh) {
489-
self.scene.remove(mesh[self.meshType])
490-
mesh[self.meshType].geometry.dispose()
489+
if (mesh.surfaceMesh) {
490+
self.scene.remove(mesh.surfaceMesh)
491+
mesh.surfaceMesh.geometry.dispose()
492+
}
493+
if (mesh.wireMesh) {
494+
mesh.wireMesh.geometry.dispose()
495+
self.scene.remove(mesh.wireMesh)
496+
}
491497
delete mesh.data
492498
delete mesh.geometry
493499
delete mesh.meshed

0 commit comments

Comments
 (0)