From 304c5d4a8b8a1137bac18f7f6443ea85cec86184 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 3 May 2013 18:48:50 +0100 Subject: [PATCH] On startup, start scenes after we're set up all local scenes, rather than starting scenes before others have been created. This aims to avoid a race condition where scenes could look to inform neighbours that they were up before those neighbours had been created. http://opensimulator.org/mantis/view.php?id=6618 --- .../LoadRegions/LoadRegionsPlugin.cs | 23 ++++++++++++------- .../RemoteController/RemoteAdminPlugin.cs | 1 + OpenSim/Framework/IScene.cs | 7 +++++- OpenSim/Region/Application/OpenSimBase.cs | 4 +--- OpenSim/Region/Framework/Scenes/Scene.cs | 16 +++++++++++-- OpenSim/Region/Framework/Scenes/SceneBase.cs | 4 ++++ 6 files changed, 41 insertions(+), 14 deletions(-) diff --git a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs index fcb6991969..1d63d2611e 100644 --- a/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs +++ b/OpenSim/ApplicationPlugins/LoadRegions/LoadRegionsPlugin.cs @@ -115,6 +115,8 @@ namespace OpenSim.ApplicationPlugins.LoadRegions Environment.Exit(1); } + List createdScenes = new List(); + for (int i = 0; i < regionsToLoad.Length; i++) { IScene scene; @@ -123,17 +125,22 @@ namespace OpenSim.ApplicationPlugins.LoadRegions ")"); bool changed = m_openSim.PopulateRegionEstateInfo(regionsToLoad[i]); + m_openSim.CreateRegion(regionsToLoad[i], true, out scene); + createdScenes.Add(scene); + if (changed) - regionsToLoad[i].EstateSettings.Save(); - - if (scene != null) + regionsToLoad[i].EstateSettings.Save(); + } + + foreach (IScene scene in createdScenes) + { + scene.Start(); + + m_newRegionCreatedHandler = OnNewRegionCreated; + if (m_newRegionCreatedHandler != null) { - m_newRegionCreatedHandler = OnNewRegionCreated; - if (m_newRegionCreatedHandler != null) - { - m_newRegionCreatedHandler(scene); - } + m_newRegionCreatedHandler(scene); } } } diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index d19b8b64b0..355f7b3078 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -700,6 +700,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController IScene newScene; m_application.CreateRegion(region, out newScene); + newScene.Start(); // If an access specification was provided, use it. // Otherwise accept the default. diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs index 87ec99ef60..8164f4198c 100644 --- a/OpenSim/Framework/IScene.cs +++ b/OpenSim/Framework/IScene.cs @@ -136,5 +136,10 @@ namespace OpenSim.Framework ISceneObject DeserializeObject(string representation); bool CheckClient(UUID agentID, System.Net.IPEndPoint ep); + + /// + /// Start the scene and associated scripts within it. + /// + void Start(); } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index d86eefe005..f9e0cf1b49 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -425,9 +425,6 @@ namespace OpenSim mscene = scene; - scene.Start(); - scene.StartScripts(); - return clientServers; } @@ -751,6 +748,7 @@ namespace OpenSim ShutdownClientServer(whichRegion); IScene scene; CreateRegion(whichRegion, true, out scene); + scene.Start(); } # region Setup methods diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 829a7e9b60..4f674a3f04 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -389,10 +389,12 @@ namespace OpenSim.Region.Framework.Scenes if (value) { if (!m_active) - Start(); + Start(false); } else { + // This appears assymetric with Start() above but is not - setting m_active = false stops the loops + // XXX: Possibly this should be in an explicit Stop() method for symmetry. m_active = false; } } @@ -1331,10 +1333,18 @@ namespace OpenSim.Region.Framework.Scenes } } + public override void Start() + { + Start(true); + } + /// /// Start the scene /// - public void Start() + /// + /// Start the scripts within the scene. + /// + public void Start(bool startScripts) { m_active = true; @@ -1353,6 +1363,8 @@ namespace OpenSim.Region.Framework.Scenes m_heartbeatThread = Watchdog.StartThread( Heartbeat, string.Format("Heartbeat ({0})", RegionInfo.RegionName), ThreadPriority.Normal, false, false); + + StartScripts(); } /// diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index d3e968e531..d2097ea7ad 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -561,6 +561,10 @@ namespace OpenSim.Region.Framework.Scenes get { return false; } } + public virtual void Start() + { + } + public void Restart() { // This has to be here to fire the event