aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-08-01 06:15:02 +0100
committerJustin Clark-Casey (justincc)2011-08-01 06:15:02 +0100
commit6618948ff9b1e98b52f3067855ca1b05e7e36144 (patch)
treeb3ef19012f0dff5d118e4c1f56731ed469324ea1
parentminor: add note to RemovePrimThreadLocked() to the effect that it contrary to... (diff)
downloadopensim-SC_OLD-6618948ff9b1e98b52f3067855ca1b05e7e36144.zip
opensim-SC_OLD-6618948ff9b1e98b52f3067855ca1b05e7e36144.tar.gz
opensim-SC_OLD-6618948ff9b1e98b52f3067855ca1b05e7e36144.tar.bz2
opensim-SC_OLD-6618948ff9b1e98b52f3067855ca1b05e7e36144.tar.xz
refactor: centralize prim geom removal code from four places to one
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsScene.cs4
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs63
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdeScene.cs24
3 files changed, 48 insertions, 43 deletions
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index 3870411..04efc1d 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -86,6 +86,10 @@ namespace OpenSim.Region.Physics.Manager
86 86
87 public abstract void RemoveAvatar(PhysicsActor actor); 87 public abstract void RemoveAvatar(PhysicsActor actor);
88 88
89 /// <summary>
90 /// Remove a prim from the physics scene.
91 /// </summary>
92 /// <param name="prim"></param>
89 public abstract void RemovePrim(PhysicsActor prim); 93 public abstract void RemovePrim(PhysicsActor prim);
90 94
91 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, 95 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 61408f0..e90df48 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -1352,7 +1352,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1352 } 1352 }
1353 1353
1354 /// <summary> 1354 /// <summary>
1355 /// Create a geometry for the given mesh/shape in the given target space. 1355 /// Create a geometry for the given mesh in the given target space.
1356 /// </summary> 1356 /// </summary>
1357 /// <param name="m_targetSpace"></param> 1357 /// <param name="m_targetSpace"></param>
1358 /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param> 1358 /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
@@ -1436,6 +1436,36 @@ Console.WriteLine("CreateGeom:");
1436 } 1436 }
1437 } 1437 }
1438 1438
1439 /// <summary>
1440 /// Remove the existing geom from this prim.
1441 /// </summary>
1442 /// <param name="m_targetSpace"></param>
1443 /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
1444 /// <returns>true if the geom was successfully removed, false if it was already gone or the remove failed.</returns>
1445 public bool RemoveGeom()
1446 {
1447 if (prim_geom != IntPtr.Zero)
1448 {
1449 try
1450 {
1451 d.GeomDestroy(prim_geom);
1452 prim_geom = IntPtr.Zero;
1453 }
1454 catch (System.AccessViolationException)
1455 {
1456 prim_geom = IntPtr.Zero;
1457 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
1458 return false;
1459 }
1460
1461 return true;
1462 }
1463 else
1464 {
1465 return false;
1466 }
1467 }
1468
1439 public void changeadd(float timestep) 1469 public void changeadd(float timestep)
1440 { 1470 {
1441 int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position); 1471 int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
@@ -1880,19 +1910,8 @@ Console.WriteLine(" JointCreateFixed");
1880 { 1910 {
1881 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) 1911 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
1882 { 1912 {
1883 if (prim_geom != IntPtr.Zero) 1913 RemoveGeom();
1884 { 1914
1885 try
1886 {
1887 d.GeomDestroy(prim_geom);
1888 prim_geom = IntPtr.Zero;
1889 }
1890 catch (System.AccessViolationException)
1891 {
1892 prim_geom = IntPtr.Zero;
1893 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
1894 }
1895 }
1896//Console.WriteLine("changePhysicsStatus for " + Name); 1915//Console.WriteLine("changePhysicsStatus for " + Name);
1897 changeadd(2f); 1916 changeadd(2f);
1898 } 1917 }
@@ -1953,8 +1972,8 @@ Console.WriteLine(" JointCreateFixed");
1953 d.SpaceRemove(m_targetSpace, prim_geom); 1972 d.SpaceRemove(m_targetSpace, prim_geom);
1954 } 1973 }
1955 1974
1956 d.GeomDestroy(prim_geom); 1975 RemoveGeom();
1957 prim_geom = IntPtr.Zero; 1976
1958 // we don't need to do space calculation because the client sends a position update also. 1977 // we don't need to do space calculation because the client sends a position update also.
1959 1978
1960 IMesh mesh = null; 1979 IMesh mesh = null;
@@ -2044,17 +2063,9 @@ Console.WriteLine(" JointCreateFixed");
2044 disableBody(); 2063 disableBody();
2045 } 2064 }
2046 } 2065 }
2047 try
2048 {
2049 d.GeomDestroy(prim_geom);
2050 }
2051 catch (System.AccessViolationException)
2052 {
2053 prim_geom = IntPtr.Zero;
2054 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
2055 }
2056 2066
2057 prim_geom = IntPtr.Zero; 2067 RemoveGeom();
2068
2058 // we don't need to do space calculation because the client sends a position update also. 2069 // we don't need to do space calculation because the client sends a position update also.
2059 if (_size.X <= 0) _size.X = 0.01f; 2070 if (_size.X <= 0) _size.X = 0.01f;
2060 if (_size.Y <= 0) _size.Y = 0.01f; 2071 if (_size.Y <= 0) _size.Y = 0.01f;
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 4419dff..3402be2 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -2094,6 +2094,8 @@ namespace OpenSim.Region.Physics.OdePlugin
2094 2094
2095 public override void RemovePrim(PhysicsActor prim) 2095 public override void RemovePrim(PhysicsActor prim)
2096 { 2096 {
2097 // As with all ODE physics operations, we don't remove the prim immediately but signal that it should be
2098 // removed in the next physics simulate pass.
2097 if (prim is OdePrim) 2099 if (prim is OdePrim)
2098 { 2100 {
2099 lock (OdeLock) 2101 lock (OdeLock)
@@ -2169,24 +2171,12 @@ namespace OpenSim.Region.Physics.OdePlugin
2169 //} 2171 //}
2170 //} 2172 //}
2171 //m_log.Warn(prim.prim_geom); 2173 //m_log.Warn(prim.prim_geom);
2172 try 2174
2173 { 2175 if (!prim.RemoveGeom())
2174 if (prim.prim_geom != IntPtr.Zero) 2176 m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene");
2175 { 2177
2176 d.GeomDestroy(prim.prim_geom);
2177 prim.prim_geom = IntPtr.Zero;
2178 }
2179 else
2180 {
2181 m_log.Warn("[PHYSICS]: Unable to remove prim from physics scene");
2182 }
2183 }
2184 catch (AccessViolationException)
2185 {
2186 m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed.");
2187 }
2188 lock (_prims) 2178 lock (_prims)
2189 _prims.Remove(prim); 2179 _prims.Remove(prim);
2190 2180
2191 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 2181 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
2192 //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) 2182 //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)