From 0079d0a7c423db6e95c04b9055127b53ae6a3622 Mon Sep 17 00:00:00 2001
From: Teravus Ovares (Dan Olivares)
Date: Fri, 16 Oct 2009 14:30:55 -0400
Subject: * One more attempt at the NullRef In The OdePlugin.   This might fix
 it, but it will definitely get us closer to the root cause.

---
 OpenSim/Region/Physics/OdePlugin/ODECharacter.cs |  2 +-
 OpenSim/Region/Physics/OdePlugin/OdePlugin.cs    | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index e5458d4..1fff846 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -1109,10 +1109,10 @@ namespace OpenSim.Region.Physics.OdePlugin
             try
             {
                 vec = d.BodyGetPosition(Body);
-                
             }
             catch (NullReferenceException)
             {
+                _parent_scene.BadCharacter(this);
                 vec = new d.Vector3(_position.X, _position.Y, _position.Z);
                 base.RaiseOutOfBounds(_position); // Tells ScenePresence that there's a problem!
                 m_log.WarnFormat("[ODEPLUGIN]: Avatar Null reference for Avatar: {0}", m_name);
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 083b7db..0e03e81 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -242,6 +242,7 @@ namespace OpenSim.Region.Physics.OdePlugin
         private readonly HashSet<OdeCharacter> _taintedActors = new HashSet<OdeCharacter>();
         private readonly List<d.ContactGeom> _perloopContact = new List<d.ContactGeom>();
         private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>();
+        private readonly HashSet<OdeCharacter> _badCharacter = new HashSet<OdeCharacter>();
         public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
         public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>();
         private bool m_NINJA_physics_joints_enabled = false;
@@ -1677,6 +1678,14 @@ namespace OpenSim.Region.Physics.OdePlugin
                 }
             }
         }
+        public void BadCharacter(OdeCharacter chr)
+        {
+            lock (_badCharacter)
+            {
+                if (!_badCharacter.Contains(chr))
+                    _badCharacter.Add(chr);
+            }
+        }
 
         public override void RemoveAvatar(PhysicsActor actor)
         {
@@ -2975,6 +2984,18 @@ namespace OpenSim.Region.Physics.OdePlugin
                     }
                 }
 
+                lock (_badCharacter)
+                {
+                    if (_badCharacter.Count > 0)
+                    {
+                        foreach (OdeCharacter chr in _badCharacter)
+                        {
+                            RemoveCharacter(chr);
+                        }
+                        _badCharacter.Clear();
+                    }
+                }
+
                 lock (_activeprims)
                 {
                     //if (timeStep < 0.2f)
-- 
cgit v1.1