Skip to content

Commit

Permalink
add method for skipping disposing
Browse files Browse the repository at this point in the history
  • Loading branch information
astrowander committed Nov 1, 2024
1 parent 79daceb commit 36a65f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions source/MRDotNet/MRMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,15 @@ public class Mesh : MeshOrPoints, IDisposable
#endregion
#region Constructors

internal Mesh(IntPtr mesh, bool needToDispose = true)
internal Mesh(IntPtr mesh)
{
mesh_ = mesh;
meshTopology_ = mrMeshTopology(mesh);
needToDispose_ = needToDispose;
}

internal void SkipDisposingAtFinalize()
{
needToDispose_ = false;
}

public void Dispose()
Expand Down
3 changes: 2 additions & 1 deletion source/MRDotNet/MRMeshLoad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public static NamedMeshList FromSceneObjFile(string path, bool combineAllObjects
var mrNamedMesh = mrVectorMeshLoadNamedMeshGet(vector, (ulong)i);
var namedMesh = new NamedMesh();
namedMesh.name = Marshal.PtrToStringAnsi(mrNamedMesh.name);
namedMesh.mesh = new Mesh(mrNamedMesh.mesh, false);
namedMesh.mesh = new Mesh(mrNamedMesh.mesh);
namedMesh.mesh.SkipDisposingAtFinalize();
namedMesh.xf = new AffineXf3f(mrNamedMesh.xf);
namedMesh.skippedFaceCount = mrNamedMesh.skippedFaceCount;
namedMesh.duplicatedVertexCount = mrNamedMesh.duplicatedVertexCount;
Expand Down

0 comments on commit 36a65f9

Please sign in to comment.