From 9c043fe41401c6334b69ef7c19001ecfc6cf8934 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 1 Jan 2019 13:16:35 +0000 Subject: [PATCH] mantis 8438: work around null ref --- OpenSim/Region/Framework/Scenes/SceneGraph.cs | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs index 6d9844e5c2..66a5325ca3 100755 --- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs +++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs @@ -69,7 +69,7 @@ namespace OpenSim.Region.Framework.Scenes #region Fields - protected System.Threading.ReaderWriterLockSlim m_scenePresencesLock = new System.Threading.ReaderWriterLockSlim(); + protected System.Threading.ReaderWriterLockSlim m_scenePresencesLock; protected ConcurrentDictionary m_scenePresenceMap = new ConcurrentDictionary(); protected ConcurrentDictionary m_scenePresenceLocalIDMap = new ConcurrentDictionary(); @@ -119,6 +119,7 @@ namespace OpenSim.Region.Framework.Scenes protected internal SceneGraph(Scene parent) { + m_scenePresencesLock = new System.Threading.ReaderWriterLockSlim(); m_parentScene = parent; } @@ -153,6 +154,9 @@ namespace OpenSim.Region.Framework.Scenes m_scenePresenceMap = new ConcurrentDictionary(); m_scenePresenceLocalIDMap = new ConcurrentDictionary(); m_scenePresenceArray = new List(); + if (_PhyScene != null) + _PhyScene.OnPhysicsCrash -= physicsBasedCrash; + _PhyScene = null; } finally { @@ -168,6 +172,7 @@ namespace OpenSim.Region.Framework.Scenes Entities.Clear(); m_scenePresencesLock.Dispose(); + m_scenePresencesLock = null; } #region Update Methods @@ -695,10 +700,13 @@ namespace OpenSim.Region.Framework.Scenes ScenePresence presence = new ScenePresence(client, m_parentScene, appearance, type); Entities[presence.UUID] = presence; + bool entered = false; - m_scenePresencesLock.EnterWriteLock(); try { + m_scenePresencesLock.EnterWriteLock(); + entered = true; + m_numChildAgents++; List newlist = new List(m_scenePresenceArray); @@ -731,7 +739,8 @@ namespace OpenSim.Region.Framework.Scenes } finally { - m_scenePresencesLock.ExitWriteLock(); + if(entered) + m_scenePresencesLock.ExitWriteLock(); } return presence; @@ -749,9 +758,11 @@ namespace OpenSim.Region.Framework.Scenes agentID); } - m_scenePresencesLock.EnterWriteLock(); + bool entered = false; try { + m_scenePresencesLock.EnterWriteLock(); + entered = true; // Remove the presence reference from the dictionary ScenePresence oldref; if(m_scenePresenceMap.TryRemove(agentID, out oldref)) @@ -769,7 +780,8 @@ namespace OpenSim.Region.Framework.Scenes } finally { - m_scenePresencesLock.ExitWriteLock(); + if(entered) + m_scenePresencesLock.ExitWriteLock(); } } @@ -896,15 +908,21 @@ namespace OpenSim.Region.Framework.Scenes /// protected internal List GetScenePresences() { - - m_scenePresencesLock.EnterReadLock(); + bool entered = false; try { + m_scenePresencesLock.EnterReadLock(); + entered = true; return m_scenePresenceArray; } + catch + { + return new List(); + } finally { - m_scenePresencesLock.ExitReadLock(); + if(entered) + m_scenePresencesLock.ExitReadLock(); } } @@ -1207,8 +1225,6 @@ namespace OpenSim.Region.Framework.Scenes { foreach (SceneObjectPart p in ((SceneObjectGroup)entity).Parts) { -// m_log.DebugFormat("[SCENE GRAPH]: Part {0} has name {1}", p.UUID, p.Name); - if (p.Name == name) { sop = p; @@ -1312,23 +1328,6 @@ namespace OpenSim.Region.Framework.Scenes /// public void ForEachScenePresence(Action action) { - // Once all callers have their delegates configured for parallelism, we can unleash this - /* - Action protectedAction = new Action(delegate(ScenePresence sp) - { - try - { - action(sp); - } - catch (Exception e) - { - m_log.Info("[SCENEGRAPH]: Error in " + m_parentScene.RegionInfo.RegionName + ": " + e.ToString()); - m_log.Info("[SCENEGRAPH]: Stack Trace: " + e.StackTrace); - } - }); - Parallel.ForEach(GetScenePresences(), protectedAction); - */ - // For now, perform actions serially List presences = GetScenePresences(); foreach (ScenePresence sp in presences) {