From 6103e06a3425de19213746e1cd6933fa2468c979 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sun, 22 Apr 2007 18:00:01 +0000 Subject: [PATCH] Added lock around World.Update to prevent multiple updates occuring simultaneously (it happened!) --- OpenSim.RegionServer/world/World.cs | 69 ++++++++++++++++------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/OpenSim.RegionServer/world/World.cs b/OpenSim.RegionServer/world/World.cs index 693db4da8f..0291467fe2 100644 --- a/OpenSim.RegionServer/world/World.cs +++ b/OpenSim.RegionServer/world/World.cs @@ -41,6 +41,7 @@ namespace OpenSim.world private string m_regionName; private InventoryCache _inventoryCache; private AssetCache _assetCache; + private int updateLock; /// /// Creates a new World class, and a region to go with it. @@ -52,6 +53,7 @@ namespace OpenSim.world { try { + updateLock = 0; m_clientThreads = clientThreads; m_regionHandle = regionHandle; m_regionName = regionName; @@ -183,48 +185,51 @@ namespace OpenSim.world /// public void Update() { - try + lock (updateLock) { - if (this.phyScene.IsThreaded) + try { - this.phyScene.GetResults(); + if (this.phyScene.IsThreaded) + { + this.phyScene.GetResults(); - } + } - foreach (libsecondlife.LLUUID UUID in Entities.Keys) - { - Entities[UUID].addForces(); - } + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].addForces(); + } - lock (this.LockPhysicsEngine) - { - this.phyScene.Simulate(timeStep); - } + lock (this.LockPhysicsEngine) + { + this.phyScene.Simulate(timeStep); + } - foreach (libsecondlife.LLUUID UUID in Entities.Keys) - { - Entities[UUID].update(); - } + foreach (libsecondlife.LLUUID UUID in Entities.Keys) + { + Entities[UUID].update(); + } - foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) - { - scriptHandler.OnFrame(); + foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values) + { + scriptHandler.OnFrame(); + } + foreach (IScriptEngine scripteng in this.scriptEngines.Values) + { + scripteng.OnFrame(); + } + //backup world data + this.storageCount++; + if (storageCount > 1200) //set to how often you want to backup + { + this.Backup(); + storageCount = 0; + } } - foreach (IScriptEngine scripteng in this.scriptEngines.Values) + catch (Exception e) { - scripteng.OnFrame(); + OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Update() - Failed with exception " + e.ToString()); } - //backup world data - this.storageCount++; - if (storageCount > 1200) //set to how often you want to backup - { - this.Backup(); - storageCount = 0; - } - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.WriteLine("World.cs: Update() - Failed with exception " + e.ToString()); } }