diff --git a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs index 636039b774..86ab58d97e 100644 --- a/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/ChOdePlugin/ODEPrim.cs @@ -704,6 +704,8 @@ namespace OpenSim.Region.Physics.OdePlugin if (m_isphysical) m_targetSpace = _parent_scene.space; + _triMeshData = IntPtr.Zero; + m_primName = primName; m_taintserial = null; m_taintadd = true; @@ -773,6 +775,8 @@ namespace OpenSim.Region.Physics.OdePlugin m_targetSpace = _parent_scene.space; } + _triMeshData = IntPtr.Zero; + m_taintserial = null; m_primName = primName; m_taintadd = true; @@ -1785,6 +1789,15 @@ namespace OpenSim.Region.Physics.OdePlugin disableBody(); } } + +// do it on caller instead +/* + if (_triMeshData != IntPtr.Zero) + { + d.GeomTriMeshDataDestroy(_triMeshData); + _triMeshData = IntPtr.Zero; + } +*/ IntPtr vertices, indices; int vertexCount, indexCount; int vertexStride, triStride; @@ -1801,14 +1814,17 @@ namespace OpenSim.Region.Physics.OdePlugin } -/* + // warning this destroys the mesh for eventual future use. Only pinned float arrays stay valid mesh.releaseSourceMeshData(); // free up the original mesh data to save memory +/* if (m_MeshToTriMeshMap.ContainsKey(mesh)) { _triMeshData = m_MeshToTriMeshMap[mesh]; } else - */ +*/ + + { _triMeshData = d.GeomTriMeshDataCreate(); @@ -1829,6 +1845,13 @@ namespace OpenSim.Region.Physics.OdePlugin catch (AccessViolationException) { m_log.Error("[PHYSICS]: MESH LOCKED"); + + if (_triMeshData != IntPtr.Zero) + { + d.GeomTriMeshDataDestroy(_triMeshData); + _triMeshData = IntPtr.Zero; + } + return false; } @@ -2302,6 +2325,12 @@ namespace OpenSim.Region.Physics.OdePlugin { bool gottrimesh = false; + if (_triMeshData != IntPtr.Zero) + { + d.GeomTriMeshDataDestroy(_triMeshData); + _triMeshData = IntPtr.Zero; + } + if (_mesh != null) // Special - make mesh { gottrimesh = setMesh(_parent_scene, _mesh); diff --git a/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs index 61fb2d00b2..f84918c7e5 100644 --- a/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/ChOdePlugin/OdePlugin.cs @@ -2174,6 +2174,16 @@ namespace OpenSim.Region.Physics.OdePlugin { prim.ResetTaints(); + try + { + if (prim._triMeshData != IntPtr.Zero) + { + d.GeomTriMeshDataDestroy(prim._triMeshData); + prim._triMeshData = IntPtr.Zero; + } + } + catch { }; + if (prim.IsPhysical) { prim.disableBody(); @@ -2185,7 +2195,6 @@ namespace OpenSim.Region.Physics.OdePlugin prim.IsPhysical = false; } - } // we don't want to remove the main space