From 36a1248b317cd80717fef6bc7c8fab318172a075 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 6 Aug 2012 09:06:46 +0100 Subject: ** DANGER someone should stress test more ** release unused physics meshs, including unmanaged memory allocations (allocated by managed code) --- OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs | 32 ++++++++---------------- OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs | 19 +++++++++++--- 2 files changed, 26 insertions(+), 25 deletions(-) (limited to 'OpenSim/Region/Physics/UbitOdePlugin') diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs index a3534a4..fbc6134 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEPrim.cs @@ -57,7 +57,6 @@ using OdeAPI; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; - namespace OpenSim.Region.Physics.OdePlugin { public class OdePrim : PhysicsActor @@ -538,24 +537,6 @@ namespace OpenSim.Region.Physics.OdePlugin { set { -/* - IMesh mesh = null; - if (_parent_scene.needsMeshing(value)) - { - bool convex; - if (m_shapetype == 0) - convex = false; - else - convex = true; - mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, (int)LevelOfDetail.High, true, convex); - } - - if (mesh != null) - { - lock (m_meshlock) - m_mesh = mesh; - } -*/ AddChange(changes.Shape, value); } } @@ -1357,7 +1338,6 @@ namespace OpenSim.Region.Physics.OdePlugin IMesh mesh = null; - lock (m_meshlock) { if (m_mesh == null) @@ -1403,7 +1383,7 @@ namespace OpenSim.Region.Physics.OdePlugin hasOOBoffsetFromMesh = true; mesh.releaseSourceMeshData(); - m_mesh = null; + m_mesh = mesh; } IntPtr geo = IntPtr.Zero; @@ -1545,7 +1525,10 @@ namespace OpenSim.Region.Physics.OdePlugin d.GeomTriMeshDataDestroy(_triMeshData); _triMeshData = IntPtr.Zero; } + } + + // catch (System.AccessViolationException) catch (Exception e) { @@ -1559,6 +1542,13 @@ namespace OpenSim.Region.Physics.OdePlugin { m_log.ErrorFormat("[PHYSICS]: PrimGeom destruction BAD {0}", Name); } + + if (m_mesh != null) + { + _parent_scene.mesher.ReleaseMesh(m_mesh); + m_mesh = null; + } + Body = IntPtr.Zero; hasOOBoffsetFromMesh = false; } diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs index f3ac3ca..3ee5198 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs @@ -194,7 +194,8 @@ namespace OpenSim.Region.Physics.OdePlugin private float metersInSpace = 25.6f; private float m_timeDilation = 1.0f; - DateTime m_lastframe; + private DateTime m_lastframe; + private DateTime m_lastMeshExpire; public float gravityx = 0f; public float gravityy = 0f; @@ -203,6 +204,8 @@ namespace OpenSim.Region.Physics.OdePlugin private float waterlevel = 0f; private int framecount = 0; + private int m_meshExpireCntr; + // private IntPtr WaterGeom = IntPtr.Zero; // private IntPtr WaterHeightmapData = IntPtr.Zero; // private GCHandle WaterMapHandler = new GCHandle(); @@ -263,7 +266,6 @@ namespace OpenSim.Region.Physics.OdePlugin const int maxContactsbeforedeath = 4000; private volatile int m_global_contactcount = 0; - private IntPtr contactgroup; public ContactData[] m_materialContactsData = new ContactData[8]; @@ -594,6 +596,7 @@ namespace OpenSim.Region.Physics.OdePlugin } m_lastframe = DateTime.UtcNow; + m_lastMeshExpire = m_lastframe; } internal void waitForSpaceUnlock(IntPtr space) @@ -1768,9 +1771,9 @@ namespace OpenSim.Region.Physics.OdePlugin { DateTime now = DateTime.UtcNow; - TimeSpan SinceLastFrame = now - m_lastframe; + TimeSpan timedif = now - m_lastframe; m_lastframe = now; - timeStep = (float)SinceLastFrame.TotalSeconds; + timeStep = (float)timedif.TotalSeconds; // acumulate time so we can reduce error step_time += timeStep; @@ -1972,6 +1975,14 @@ namespace OpenSim.Region.Physics.OdePlugin _badCharacter.Clear(); } } + + timedif = now - m_lastMeshExpire; + + if (timedif.Seconds > 10) + { + mesher.ExpireReleaseMeshs(); + m_lastMeshExpire = now; + } /* int nactivegeoms = d.SpaceGetNumGeoms(ActiveSpace); int nstaticgeoms = d.SpaceGetNumGeoms(StaticSpace); -- cgit v1.1