diff options
author | Justin Clark-Casey (justincc) | 2012-04-21 00:12:07 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-04-21 00:12:07 +0100 |
commit | 7a574be3fd28ffbd9bce4cfa08451d705728fa20 (patch) | |
tree | 6efe638d29bf90a65ee308eea51a815d23492818 /OpenSim/Region/Physics | |
parent | Improve bitmap disposal to do null checks and not to potentially try disposal... (diff) | |
download | opensim-SC-7a574be3fd28ffbd9bce4cfa08451d705728fa20.zip opensim-SC-7a574be3fd28ffbd9bce4cfa08451d705728fa20.tar.gz opensim-SC-7a574be3fd28ffbd9bce4cfa08451d705728fa20.tar.bz2 opensim-SC-7a574be3fd28ffbd9bce4cfa08451d705728fa20.tar.xz |
Remove redundant prim_geom != IntPtr.Zero checks in ODEPrim.
prim_geom == IntPtr.Zero only before a new add prim taint is processed (which is the first taint) or in operations such as scale change which are done in taint or under lock.
Therefore, we can remove these checks which were not consistently applied anyway.
If there is a genuine problem, better to see it quickly in a NullReferenceException than hide the bug.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | 204 |
1 files changed, 88 insertions, 116 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs index 7d67da3..0a8cf75 100644 --- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs +++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs | |||
@@ -156,7 +156,15 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
156 | /// </summary> | 156 | /// </summary> |
157 | public IntPtr m_targetSpace = IntPtr.Zero; | 157 | public IntPtr m_targetSpace = IntPtr.Zero; |
158 | 158 | ||
159 | /// <summary> | ||
160 | /// The prim geometry, used for collision detection. | ||
161 | /// </summary> | ||
162 | /// <remarks> | ||
163 | /// This is never null except for a brief period when the geometry needs to be replaced (due to resizing or | ||
164 | /// mesh change) or when the physical prim is being removed from the scene. | ||
165 | /// </remarks> | ||
159 | public IntPtr prim_geom { get; private set; } | 166 | public IntPtr prim_geom { get; private set; } |
167 | |||
160 | public IntPtr _triMeshData { get; private set; } | 168 | public IntPtr _triMeshData { get; private set; } |
161 | 169 | ||
162 | private IntPtr _linkJointGroup = IntPtr.Zero; | 170 | private IntPtr _linkJointGroup = IntPtr.Zero; |
@@ -325,14 +333,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
325 | { | 333 | { |
326 | prim_geom = geom; | 334 | prim_geom = geom; |
327 | //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name); | 335 | //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name); |
328 | if (prim_geom != IntPtr.Zero) | ||
329 | { | ||
330 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); | ||
331 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | ||
332 | 336 | ||
333 | _parent_scene.geom_name_map[prim_geom] = Name; | 337 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); |
334 | _parent_scene.actor_name_map[prim_geom] = this; | 338 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
335 | } | 339 | |
340 | _parent_scene.geom_name_map[prim_geom] = Name; | ||
336 | 341 | ||
337 | if (childPrim) | 342 | if (childPrim) |
338 | { | 343 | { |
@@ -765,11 +770,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
765 | m_collisionCategories &= ~CollisionCategories.Body; | 770 | m_collisionCategories &= ~CollisionCategories.Body; |
766 | m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); | 771 | m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); |
767 | 772 | ||
768 | if (prim_geom != IntPtr.Zero) | 773 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); |
769 | { | 774 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
770 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); | ||
771 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | ||
772 | } | ||
773 | 775 | ||
774 | d.BodyDestroy(Body); | 776 | d.BodyDestroy(Body); |
775 | lock (childrenPrim) | 777 | lock (childrenPrim) |
@@ -793,11 +795,8 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
793 | m_collisionCategories &= ~CollisionCategories.Body; | 795 | m_collisionCategories &= ~CollisionCategories.Body; |
794 | m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); | 796 | m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); |
795 | 797 | ||
796 | if (prim_geom != IntPtr.Zero) | 798 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); |
797 | { | 799 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
798 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); | ||
799 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | ||
800 | } | ||
801 | 800 | ||
802 | Body = IntPtr.Zero; | 801 | Body = IntPtr.Zero; |
803 | } | 802 | } |
@@ -864,10 +863,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
864 | // _parent_scene.waitForSpaceUnlock(m_targetSpace); | 863 | // _parent_scene.waitForSpaceUnlock(m_targetSpace); |
865 | try | 864 | try |
866 | { | 865 | { |
867 | if (prim_geom == IntPtr.Zero) | 866 | SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); |
868 | { | ||
869 | SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); | ||
870 | } | ||
871 | } | 867 | } |
872 | catch (AccessViolationException) | 868 | catch (AccessViolationException) |
873 | { | 869 | { |
@@ -890,73 +886,67 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
890 | #if SPAM | 886 | #if SPAM |
891 | Console.WriteLine("ZProcessTaints for " + Name); | 887 | Console.WriteLine("ZProcessTaints for " + Name); |
892 | #endif | 888 | #endif |
889 | |||
890 | // This must be processed as the very first taint so that later operations have a prim_geom to work with | ||
891 | // if this is a new prim. | ||
893 | if (m_taintadd) | 892 | if (m_taintadd) |
894 | { | ||
895 | changeadd(); | 893 | changeadd(); |
896 | } | ||
897 | |||
898 | if (prim_geom != IntPtr.Zero) | ||
899 | { | ||
900 | if (!_position.ApproxEquals(m_taintposition, 0f)) | ||
901 | changemove(); | ||
902 | 894 | ||
903 | if (m_taintrot != _orientation) | 895 | if (!_position.ApproxEquals(m_taintposition, 0f)) |
904 | { | 896 | changemove(); |
905 | if (childPrim && IsPhysical) // For physical child prim... | 897 | |
906 | { | 898 | if (m_taintrot != _orientation) |
907 | rotate(); | 899 | { |
908 | // KF: ODE will also rotate the parent prim! | 900 | if (childPrim && IsPhysical) // For physical child prim... |
909 | // so rotate the root back to where it was | 901 | { |
910 | OdePrim parent = (OdePrim)_parent; | 902 | rotate(); |
911 | parent.rotate(); | 903 | // KF: ODE will also rotate the parent prim! |
912 | } | 904 | // so rotate the root back to where it was |
913 | else | 905 | OdePrim parent = (OdePrim)_parent; |
914 | { | 906 | parent.rotate(); |
915 | //Just rotate the prim | ||
916 | rotate(); | ||
917 | } | ||
918 | } | 907 | } |
919 | 908 | else | |
920 | if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent)) | 909 | { |
921 | changePhysicsStatus(); | 910 | //Just rotate the prim |
911 | rotate(); | ||
912 | } | ||
913 | } | ||
914 | |||
915 | if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent)) | ||
916 | changePhysicsStatus(); | ||
922 | 917 | ||
923 | if (!_size.ApproxEquals(m_taintsize, 0f)) | 918 | if (!_size.ApproxEquals(m_taintsize, 0f)) |
924 | changesize(); | 919 | changesize(); |
925 | 920 | ||
926 | if (m_taintshape) | 921 | if (m_taintshape) |
927 | changeshape(); | 922 | changeshape(); |
928 | 923 | ||
929 | if (m_taintforce) | 924 | if (m_taintforce) |
930 | changeAddForce(); | 925 | changeAddForce(); |
931 | 926 | ||
932 | if (m_taintaddangularforce) | 927 | if (m_taintaddangularforce) |
933 | changeAddAngularForce(); | 928 | changeAddAngularForce(); |
934 | 929 | ||
935 | if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f)) | 930 | if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f)) |
936 | changeSetTorque(); | 931 | changeSetTorque(); |
937 | 932 | ||
938 | if (m_taintdisable) | 933 | if (m_taintdisable) |
939 | changedisable(); | 934 | changedisable(); |
940 | 935 | ||
941 | if (m_taintselected != m_isSelected) | 936 | if (m_taintselected != m_isSelected) |
942 | changeSelectedStatus(); | 937 | changeSelectedStatus(); |
943 | 938 | ||
944 | if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f)) | 939 | if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f)) |
945 | changevelocity(); | 940 | changevelocity(); |
946 | 941 | ||
947 | if (m_taintparent != _parent) | 942 | if (m_taintparent != _parent) |
948 | changelink(); | 943 | changelink(); |
949 | 944 | ||
950 | if (m_taintCollidesWater != m_collidesWater) | 945 | if (m_taintCollidesWater != m_collidesWater) |
951 | changefloatonwater(); | 946 | changefloatonwater(); |
952 | 947 | ||
953 | if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f)) | 948 | if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f)) |
954 | changeAngularLock(); | 949 | changeAngularLock(); |
955 | } | ||
956 | else | ||
957 | { | ||
958 | m_log.ErrorFormat("[PHYSICS]: The scene reused a disposed PhysActor for {0}! *waves finger*, Don't be evil. A couple of things can cause this. An improper prim breakdown(be sure to set prim_geom to zero after d.GeomDestroy! An improper buildup (creating the geom failed). Or, the Scene Reused a physics actor after disposing it.)", Name); | ||
959 | } | ||
960 | } | 950 | } |
961 | 951 | ||
962 | /// <summary> | 952 | /// <summary> |
@@ -1093,18 +1083,10 @@ Console.WriteLine("ZProcessTaints for " + Name); | |||
1093 | prm.m_collisionCategories |= CollisionCategories.Body; | 1083 | prm.m_collisionCategories |= CollisionCategories.Body; |
1094 | prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); | 1084 | prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); |
1095 | 1085 | ||
1096 | if (prm.prim_geom == IntPtr.Zero) | ||
1097 | { | ||
1098 | m_log.WarnFormat( | ||
1099 | "[PHYSICS]: Unable to link one of the linkset elements {0} for parent {1}. No geom yet", | ||
1100 | prm.Name, prim.Name); | ||
1101 | continue; | ||
1102 | } | ||
1103 | //Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name); | 1086 | //Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name); |
1104 | d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories); | 1087 | d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories); |
1105 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); | 1088 | d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); |
1106 | 1089 | ||
1107 | |||
1108 | d.Quaternion quat = new d.Quaternion(); | 1090 | d.Quaternion quat = new d.Quaternion(); |
1109 | quat.W = prm._orientation.W; | 1091 | quat.W = prm._orientation.W; |
1110 | quat.X = prm._orientation.X; | 1092 | quat.X = prm._orientation.X; |
@@ -1303,11 +1285,8 @@ Console.WriteLine("ZProcessTaints for " + Name); | |||
1303 | disableBodySoft(); | 1285 | disableBodySoft(); |
1304 | } | 1286 | } |
1305 | 1287 | ||
1306 | if (prim_geom != IntPtr.Zero) | 1288 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); |
1307 | { | 1289 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
1308 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); | ||
1309 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | ||
1310 | } | ||
1311 | 1290 | ||
1312 | if (IsPhysical) | 1291 | if (IsPhysical) |
1313 | { | 1292 | { |
@@ -1328,11 +1307,8 @@ Console.WriteLine("ZProcessTaints for " + Name); | |||
1328 | if (m_collidesWater) | 1307 | if (m_collidesWater) |
1329 | m_collisionFlags |= CollisionCategories.Water; | 1308 | m_collisionFlags |= CollisionCategories.Water; |
1330 | 1309 | ||
1331 | if (prim_geom != IntPtr.Zero) | 1310 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); |
1332 | { | 1311 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); |
1333 | d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); | ||
1334 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | ||
1335 | } | ||
1336 | 1312 | ||
1337 | if (IsPhysical) | 1313 | if (IsPhysical) |
1338 | { | 1314 | { |
@@ -1472,6 +1448,9 @@ Console.WriteLine("CreateGeom:"); | |||
1472 | } | 1448 | } |
1473 | else | 1449 | else |
1474 | { | 1450 | { |
1451 | m_log.WarnFormat( | ||
1452 | "[ODE PRIM]: Called RemoveGeom() on {0} {1} where geometry was already null.", Name, LocalID); | ||
1453 | |||
1475 | return false; | 1454 | return false; |
1476 | } | 1455 | } |
1477 | } | 1456 | } |
@@ -1505,16 +1484,13 @@ Console.WriteLine("changeadd 1"); | |||
1505 | #endif | 1484 | #endif |
1506 | CreateGeom(m_targetSpace, mesh); | 1485 | CreateGeom(m_targetSpace, mesh); |
1507 | 1486 | ||
1508 | if (prim_geom != IntPtr.Zero) | 1487 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); |
1509 | { | 1488 | d.Quaternion myrot = new d.Quaternion(); |
1510 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | 1489 | myrot.X = _orientation.X; |
1511 | d.Quaternion myrot = new d.Quaternion(); | 1490 | myrot.Y = _orientation.Y; |
1512 | myrot.X = _orientation.X; | 1491 | myrot.Z = _orientation.Z; |
1513 | myrot.Y = _orientation.Y; | 1492 | myrot.W = _orientation.W; |
1514 | myrot.Z = _orientation.Z; | 1493 | d.GeomSetQuaternion(prim_geom, ref myrot); |
1515 | myrot.W = _orientation.W; | ||
1516 | d.GeomSetQuaternion(prim_geom, ref myrot); | ||
1517 | } | ||
1518 | 1494 | ||
1519 | if (IsPhysical && Body == IntPtr.Zero) | 1495 | if (IsPhysical && Body == IntPtr.Zero) |
1520 | enableBody(); | 1496 | enableBody(); |
@@ -1588,13 +1564,11 @@ Console.WriteLine(" JointCreateFixed"); | |||
1588 | m_targetSpace = tempspace; | 1564 | m_targetSpace = tempspace; |
1589 | 1565 | ||
1590 | // _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1566 | // _parent_scene.waitForSpaceUnlock(m_targetSpace); |
1591 | if (prim_geom != IntPtr.Zero) | 1567 | |
1592 | { | 1568 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); |
1593 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | ||
1594 | 1569 | ||
1595 | // _parent_scene.waitForSpaceUnlock(m_targetSpace); | 1570 | // _parent_scene.waitForSpaceUnlock(m_targetSpace); |
1596 | d.SpaceAdd(m_targetSpace, prim_geom); | 1571 | d.SpaceAdd(m_targetSpace, prim_geom); |
1597 | } | ||
1598 | 1572 | ||
1599 | changeSelectedStatus(); | 1573 | changeSelectedStatus(); |
1600 | 1574 | ||
@@ -2045,18 +2019,16 @@ Console.WriteLine(" JointCreateFixed"); | |||
2045 | { | 2019 | { |
2046 | m_collidesWater = m_taintCollidesWater; | 2020 | m_collidesWater = m_taintCollidesWater; |
2047 | 2021 | ||
2048 | if (prim_geom != IntPtr.Zero) | 2022 | if (m_collidesWater) |
2049 | { | 2023 | { |
2050 | if (m_collidesWater) | 2024 | m_collisionFlags |= CollisionCategories.Water; |
2051 | { | 2025 | } |
2052 | m_collisionFlags |= CollisionCategories.Water; | 2026 | else |
2053 | } | 2027 | { |
2054 | else | 2028 | m_collisionFlags &= ~CollisionCategories.Water; |
2055 | { | ||
2056 | m_collisionFlags &= ~CollisionCategories.Water; | ||
2057 | } | ||
2058 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | ||
2059 | } | 2029 | } |
2030 | |||
2031 | d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); | ||
2060 | } | 2032 | } |
2061 | 2033 | ||
2062 | /// <summary> | 2034 | /// <summary> |