diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c2722ca..f64f039d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -207,7 +207,7 @@ jobs: echo "Initial free space" df -h / echo "Removing all pre-loaded docker images" - docker rmi $(docker image ls -aq) # Removes ~3GB + docker image ls -aq | xargs -r docker rmi # Removes ~3GB df -h / echo "Listing 100 largest packages" dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | head -n 100 diff --git a/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs b/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs index 2ac21955..6f18c996 100644 --- a/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs +++ b/Assets/Scripts/model/core/MeshWithMaterialRenderer.cs @@ -51,6 +51,14 @@ public void UsePreviewShader(bool usePreview) // Which Layer this mesh will be drawn to. public int Layer = DEFAULT_LAYER; + public void OnDestroy() + { + foreach (MeshWithMaterial meshWithMaterial in meshes) + { + Destroy(meshWithMaterial.mesh); + } + } + public void Init(WorldSpace worldSpace) { this.worldSpace = worldSpace; diff --git a/Assets/Scripts/model/main/PeltzerMain.cs b/Assets/Scripts/model/main/PeltzerMain.cs index b443af10..e96b28e3 100644 --- a/Assets/Scripts/model/main/PeltzerMain.cs +++ b/Assets/Scripts/model/main/PeltzerMain.cs @@ -1550,6 +1550,8 @@ public void CreateNewModel(bool clearReferenceImages = true, bool resetAttention zoomer.ClearState(); model.Clear(worldSpace); volumeInserter.ClearState(); + MeshCycler.DestroyMeshes(); + spatialIndex.Reset(DEFAULT_BOUNDS); if (resetAttentionCaller) { diff --git a/Assets/Scripts/model/render/MeshHelper.cs b/Assets/Scripts/model/render/MeshHelper.cs index e6c54f7d..30f17413 100644 --- a/Assets/Scripts/model/render/MeshHelper.cs +++ b/Assets/Scripts/model/render/MeshHelper.cs @@ -21,6 +21,7 @@ using com.google.apps.peltzer.client.model.import; using com.google.apps.peltzer.client.model.main; using com.google.apps.peltzer.client.model.util; +using Object = System.Object; namespace com.google.apps.peltzer.client.model.render { @@ -165,6 +166,11 @@ public static void UpdateMeshes(MMesh updatedMesh, List existi newPos.Count != uMesh.mesh.vertices.Count()) { // If materials changed, easiest action is to remesh everything. + foreach (var mm in existing) + { + UnityEngine.Object.Destroy(mm.mesh); + UnityEngine.Object.Destroy(mm.materialAndColor.material); + } existing.Clear(); // This method is used to update a GameObject, and as such we do not want the vert positions in model space, // it is the gameObject that will be placed and rotated in the world. diff --git a/Assets/Scripts/model/render/ReMesher.cs b/Assets/Scripts/model/render/ReMesher.cs index 836fc2b6..85558645 100644 --- a/Assets/Scripts/model/render/ReMesher.cs +++ b/Assets/Scripts/model/render/ReMesher.cs @@ -19,6 +19,8 @@ using com.google.apps.peltzer.client.model.core; using com.google.apps.peltzer.client.model.util; using com.google.apps.peltzer.client.model.main; +using UnityEditor; +using Object = UnityEngine.Object; namespace com.google.apps.peltzer.client.model.render { @@ -342,8 +344,14 @@ public static void InitBufferCaches() public void Clear() { - meshInfosByMaterial.Clear(); + foreach (var meshInfo in allMeshInfos) + { + Object.Destroy(meshInfo.mesh); + Object.Destroy(meshInfo.materialAndColor.material); + } allMeshInfos.Clear(); + meshInfosByMaterial.Clear(); + meshInfosByMesh.Clear(); meshesPendingAdd.Clear(); meshesPendingRemove.Clear(); meshInfosPendingRegeneration.Clear(); diff --git a/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs b/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs index b9a11379..14560190 100644 --- a/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs +++ b/Assets/Scripts/tools/utils/HighlightStyles/MeshCycler.cs @@ -86,5 +86,15 @@ public static void ResetCycler() } meshDict.Clear(); } + + public static void DestroyMeshes() + { + ResetCycler(); + foreach (Mesh mesh in meshPool) + { + Object.Destroy(mesh); + } + meshPool.Clear(); + } } }