avoid potencial null ref

master
UbitUmarov 2020-05-26 15:16:37 +01:00
parent d2dbe3f4d0
commit 182b266ec4
1 changed files with 23 additions and 13 deletions

View File

@ -3984,7 +3984,7 @@ namespace OpenSim.Region.Framework.Scenes
// We need to ensure that we are not already removing the scene presence before we ask it not to be // We need to ensure that we are not already removing the scene presence before we ask it not to be
// closed. // closed.
if (sp != null && sp.IsChildAgent if (sp != null && !sp.IsDeleted && sp.IsChildAgent
&& (sp.LifecycleState == ScenePresenceState.Running && (sp.LifecycleState == ScenePresenceState.Running
|| sp.LifecycleState == ScenePresenceState.PreRemove)) || sp.LifecycleState == ScenePresenceState.PreRemove))
{ {
@ -4033,28 +4033,38 @@ namespace OpenSim.Region.Framework.Scenes
const int pollInterval = 1000; const int pollInterval = 1000;
int pollsLeft = polls; int pollsLeft = polls;
while (sp.LifecycleState == ScenePresenceState.Removing && pollsLeft-- > 0) try
Thread.Sleep(pollInterval);
if (sp.LifecycleState == ScenePresenceState.Removing)
{ {
m_log.WarnFormat( while (!sp.IsDeleted && sp.LifecycleState == ScenePresenceState.Removing && pollsLeft-- > 0)
"[SCENE]: Agent {0} in {1} was still being removed after {2}s. Aborting NewUserConnection.", Thread.Sleep(pollInterval);
sp.Name, Name, polls * pollInterval / 1000);
return false; if (!sp.IsDeleted && sp.LifecycleState == ScenePresenceState.Removing)
{
m_log.WarnFormat(
"[SCENE]: Agent {0} in {1} was still being removed after {2}s. Aborting NewUserConnection.",
sp.Name, Name, polls * pollInterval / 1000);
return false;
}
else if (polls != pollsLeft)
{
m_log.DebugFormat(
"[SCENE]: NewUserConnection for agent {0} in {1} had to wait {2}s for in-progress removal to complete on an old presence.",
sp.Name, Name, polls * pollInterval / 1000);
}
} }
else if (polls != pollsLeft) catch
{ {
m_log.DebugFormat( sp = null;
"[SCENE]: NewUserConnection for agent {0} in {1} had to wait {2}s for in-progress removal to complete on an old presence.",
sp.Name, Name, polls * pollInterval / 1000);
} }
} }
// TODO: can we remove this lock? // TODO: can we remove this lock?
lock (m_newUserConnLock) lock (m_newUserConnLock)
{ {
if(sp != null && sp.IsDeleted)
sp = null;
if (sp != null && !sp.IsChildAgent) if (sp != null && !sp.IsChildAgent)
{ {
// We have a root agent. Is it in transit? // We have a root agent. Is it in transit?