From d3b013be1cdbf2c89847a3e900a6eeacdad5486e Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Sun, 25 May 2008 02:39:58 +0000 Subject: * Releases Pinned vertex/index list in ODE on next mesh request. --- OpenSim/Region/Physics/Manager/IMesher.cs | 2 ++ OpenSim/Region/Physics/Meshing/Mesh.cs | 14 +++++++++++--- OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/Manager/IMesher.cs b/OpenSim/Region/Physics/Manager/IMesher.cs index ee498c5..b5fc95c 100644 --- a/OpenSim/Region/Physics/Manager/IMesher.cs +++ b/OpenSim/Region/Physics/Manager/IMesher.cs @@ -46,5 +46,7 @@ namespace OpenSim.Region.Physics.Manager int[] getIndexListAsInt(); int[] getIndexListAsIntLocked(); float[] getVertexListAsFloatLocked(); + void releasePinned(); + } } diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs index 1b0444b..652bbd7 100644 --- a/OpenSim/Region/Physics/Meshing/Mesh.cs +++ b/OpenSim/Region/Physics/Meshing/Mesh.cs @@ -37,7 +37,8 @@ namespace OpenSim.Region.Physics.Meshing { public List vertices; public List triangles; - + GCHandle pinnedVirtexes; + GCHandle pinnedIndex; public float[] normals; public Mesh() @@ -164,7 +165,7 @@ namespace OpenSim.Region.Physics.Meshing result[3*i + 1] = v.Y; result[3*i + 2] = v.Z; } - GCHandle.Alloc(result, GCHandleType.Pinned); + pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned); return result; } @@ -184,10 +185,17 @@ namespace OpenSim.Region.Physics.Meshing public int[] getIndexListAsIntLocked() { int[] result = getIndexListAsInt(); - GCHandle.Alloc(result, GCHandleType.Pinned); + pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned); return result; } + public void releasePinned() + { + pinnedVirtexes.Free(); + pinnedIndex.Free(); + + } + public void Append(Mesh newMesh) { diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 1ba4bb1..4c8eb20 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs @@ -69,6 +69,7 @@ namespace OpenSim.Region.Physics.OdePlugin private float PID_G = 25f; private float m_tensor = 5f; private int body_autodisable_frames = 20; + private IMesh primMesh = null; private bool m_usePID = false; @@ -674,8 +675,13 @@ namespace OpenSim.Region.Physics.OdePlugin disableBody(); } - float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory - int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage + IMesh oldMesh = primMesh; + + primMesh = mesh; + + float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory + int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage + int VertexCount = vertexList.GetLength(0)/3; int IndexCount = indexList.GetLength(0); @@ -699,6 +705,13 @@ namespace OpenSim.Region.Physics.OdePlugin m_log.Error("[PHYSICS]: MESH LOCKED"); return; } + + if (oldMesh != null) + { + oldMesh.releasePinned(); + oldMesh = null; + } + if (IsPhysical && Body == (IntPtr) 0) { // Recreate the body -- cgit v1.1