Skip to content

Commit

Permalink
Dispose of any mesh, instead of current mesh -- allows for dynamicall…
Browse files Browse the repository at this point in the history
…y 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).
  • Loading branch information
deathcap committed Dec 8, 2013
1 parent 47a05ba commit c845d3f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,14 @@ Game.prototype.removeFarChunks = function(playerPosition) {
if (!chunk) return
var chunkPosition = chunk.position
if (mesh) {
self.scene.remove(mesh[self.meshType])
mesh[self.meshType].geometry.dispose()
if (mesh.surfaceMesh) {
self.scene.remove(mesh.surfaceMesh)
mesh.surfaceMesh.geometry.dispose()
}
if (mesh.wireMesh) {
mesh.wireMesh.geometry.dispose()
self.scene.remove(mesh.wireMesh)
}
delete mesh.data
delete mesh.geometry
delete mesh.meshed
Expand Down

0 comments on commit c845d3f

Please sign in to comment.