diff options
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/OdePlugin.cs')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 178 |
1 files changed, 92 insertions, 86 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 3d70a3d..d7d9ab1 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -330,6 +330,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
330 | catch (SEHException) | 330 | catch (SEHException) |
331 | { | 331 | { |
332 | m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); | 332 | m_log.Error("[PHYSICS]: The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); |
333 | ode.drelease(world); | ||
333 | base.TriggerPhysicsBasedRestart(); | 334 | base.TriggerPhysicsBasedRestart(); |
334 | } | 335 | } |
335 | catch (System.AccessViolationException) | 336 | catch (System.AccessViolationException) |
@@ -737,87 +738,92 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
737 | /// <param name="prim"></param> | 738 | /// <param name="prim"></param> |
738 | public void RemovePrimThreadLocked(OdePrim prim) | 739 | public void RemovePrimThreadLocked(OdePrim prim) |
739 | { | 740 | { |
740 | while (ode.lockquery()) | 741 | lock (ode) |
741 | { | 742 | { |
742 | } | 743 | if (prim.prim_geom != (IntPtr)0) |
743 | ode.dlock(world); | ||
744 | //System.Threading.Thread.Sleep(20); | ||
745 | prim.ResetTaints(); | ||
746 | |||
747 | |||
748 | if (prim.IsPhysical) | ||
749 | { | ||
750 | prim.disableBody(); | ||
751 | } | ||
752 | // we don't want to remove the main space | ||
753 | if (prim.m_targetSpace != space && prim.IsPhysical == false) | ||
754 | { | 744 | { |
755 | // If the geometry is in the targetspace, remove it from the target space | 745 | while (ode.lockquery()) |
756 | //m_log.Warn(prim.m_targetSpace); | 746 | { |
757 | if (prim.prim_geom == (IntPtr)0) | 747 | } |
758 | prim.prim_geom = prim.prev_geom; | 748 | ode.dlock(world); |
749 | //System.Threading.Thread.Sleep(20); | ||
750 | prim.ResetTaints(); | ||
751 | |||
759 | 752 | ||
760 | if (prim.m_targetSpace != (IntPtr)0) | 753 | if (prim.IsPhysical) |
761 | { | 754 | { |
762 | if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom)) | 755 | prim.disableBody(); |
756 | } | ||
757 | // we don't want to remove the main space | ||
758 | if (prim.m_targetSpace != space && prim.IsPhysical == false) | ||
759 | { | ||
760 | // If the geometry is in the targetspace, remove it from the target space | ||
761 | //m_log.Warn(prim.m_targetSpace); | ||
762 | |||
763 | |||
764 | if (prim.m_targetSpace != (IntPtr)0) | ||
763 | { | 765 | { |
764 | 766 | if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom)) | |
765 | if (d.GeomIsSpace(prim.m_targetSpace)) | ||
766 | { | 767 | { |
767 | waitForSpaceUnlock(prim.m_targetSpace); | 768 | |
768 | d.SpaceRemove(prim.m_targetSpace, prim.prim_geom); | 769 | if (d.GeomIsSpace(prim.m_targetSpace)) |
769 | prim.m_targetSpace = space; | 770 | { |
771 | waitForSpaceUnlock(prim.m_targetSpace); | ||
772 | d.SpaceRemove(prim.m_targetSpace, prim.prim_geom); | ||
773 | prim.m_targetSpace = space; | ||
774 | } | ||
775 | else | ||
776 | { | ||
777 | m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + | ||
778 | ((OdePrim)prim).m_targetSpace.ToString()); | ||
779 | } | ||
780 | |||
770 | } | 781 | } |
771 | else | 782 | } |
783 | //m_log.Warn(prim.prim_geom); | ||
784 | try | ||
785 | { | ||
786 | if (prim.prim_geom != (IntPtr)0) | ||
772 | { | 787 | { |
773 | m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + | 788 | d.GeomDestroy(prim.prim_geom); |
774 | ((OdePrim)prim).m_targetSpace.ToString()); | 789 | prim.prim_geom = (IntPtr)0; |
775 | } | 790 | } |
776 | 791 | ||
777 | } | 792 | } |
778 | } | 793 | catch (System.AccessViolationException) |
779 | //m_log.Warn(prim.prim_geom); | ||
780 | try | ||
781 | { | ||
782 | if (prim.prim_geom != (IntPtr)0) | ||
783 | { | 794 | { |
784 | d.GeomDestroy(prim.prim_geom); | 795 | m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed."); |
785 | prim.prim_geom = (IntPtr) 0; | ||
786 | } | 796 | } |
787 | 797 | _prims.Remove(prim); | |
788 | } | ||
789 | catch (System.AccessViolationException) | ||
790 | { | ||
791 | m_log.Info("[PHYSICS]: Couldn't remove prim from physics scene, it was already be removed."); | ||
792 | } | ||
793 | _prims.Remove(prim); | ||
794 | 798 | ||
795 | //If there are no more geometries in the sub-space, we don't need it in the main space anymore | 799 | //If there are no more geometries in the sub-space, we don't need it in the main space anymore |
796 | //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) | 800 | //if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) |
797 | //{ | 801 | //{ |
798 | //if (!(prim.m_targetSpace.Equals(null))) | 802 | //if (!(prim.m_targetSpace.Equals(null))) |
799 | //{ | 803 | //{ |
800 | //if (d.GeomIsSpace(prim.m_targetSpace)) | 804 | //if (d.GeomIsSpace(prim.m_targetSpace)) |
801 | //{ | 805 | //{ |
802 | //waitForSpaceUnlock(prim.m_targetSpace); | 806 | //waitForSpaceUnlock(prim.m_targetSpace); |
803 | //d.SpaceRemove(space, prim.m_targetSpace); | 807 | //d.SpaceRemove(space, prim.m_targetSpace); |
804 | // free up memory used by the space. | 808 | // free up memory used by the space. |
805 | //d.SpaceDestroy(prim.m_targetSpace); | 809 | //d.SpaceDestroy(prim.m_targetSpace); |
806 | //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position); | 810 | //int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position); |
807 | //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]); | 811 | //resetSpaceArrayItemToZero(xyspace[0], xyspace[1]); |
808 | //} | ||
809 | //else | ||
810 | //{ | ||
811 | //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + | ||
812 | //((OdePrim) prim).m_targetSpace.ToString()); | ||
813 | //} | ||
814 | //} | 812 | //} |
815 | //} | 813 | //else |
816 | } | 814 | //{ |
815 | //m_log.Info("[Physics]: Invalid Scene passed to 'removeprim from scene':" + | ||
816 | //((OdePrim) prim).m_targetSpace.ToString()); | ||
817 | //} | ||
818 | //} | ||
819 | //} | ||
820 | } | ||
821 | |||
822 | |||
817 | 823 | ||
818 | 824 | ode.dunlock(world); | |
819 | 825 | } | |
820 | ode.dunlock(world); | 826 | } |
821 | } | 827 | } |
822 | /// <summary> | 828 | /// <summary> |
823 | /// Takes a space pointer and zeros out the array we're using to hold the spaces | 829 | /// Takes a space pointer and zeros out the array we're using to hold the spaces |
@@ -1238,6 +1244,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1238 | catch (StackOverflowException) | 1244 | catch (StackOverflowException) |
1239 | { | 1245 | { |
1240 | m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); | 1246 | m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); |
1247 | ode.drelease(world); | ||
1241 | base.TriggerPhysicsBasedRestart(); | 1248 | base.TriggerPhysicsBasedRestart(); |
1242 | } | 1249 | } |
1243 | 1250 | ||
@@ -1249,33 +1256,32 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1249 | 1256 | ||
1250 | while (step_time > 0.0f) | 1257 | while (step_time > 0.0f) |
1251 | { | 1258 | { |
1252 | foreach (OdeCharacter actor in _characters) | 1259 | lock (ode) |
1253 | { | 1260 | { |
1254 | actor.Move(timeStep); | 1261 | if (!ode.lockquery()) |
1255 | actor.collidelock = true; | 1262 | { |
1256 | } | 1263 | ode.dlock(world); |
1257 | if (!ode.lockquery()) | 1264 | foreach (OdeCharacter actor in _characters) |
1258 | { | 1265 | { |
1259 | ode.dlock(world); | 1266 | actor.Move(timeStep); |
1267 | |||
1268 | } | ||
1269 | |||
1260 | 1270 | ||
1261 | collision_optimized(timeStep); | 1271 | collision_optimized(timeStep); |
1262 | 1272 | ||
1263 | d.WorldQuickStep(world, ODE_STEPSIZE); | 1273 | d.WorldQuickStep(world, ODE_STEPSIZE); |
1264 | |||
1265 | d.JointGroupEmpty(contactgroup); | ||
1266 | ode.dunlock(world); | ||
1267 | 1274 | ||
1268 | step_time -= ODE_STEPSIZE; | 1275 | d.JointGroupEmpty(contactgroup); |
1269 | i++; | 1276 | ode.dunlock(world); |
1270 | } | ||
1271 | else | ||
1272 | { | ||
1273 | fps = 0; | ||
1274 | } | ||
1275 | 1277 | ||
1276 | foreach (OdeCharacter actor in _characters) | 1278 | step_time -= ODE_STEPSIZE; |
1277 | { | 1279 | i++; |
1278 | actor.collidelock = false; | 1280 | } |
1281 | else | ||
1282 | { | ||
1283 | fps = 0; | ||
1284 | } | ||
1279 | } | 1285 | } |
1280 | } | 1286 | } |
1281 | 1287 | ||