Register the UrlModule for script engine events OnScriptRemoved and OnObjectRemoved just once in the UrlModule itself, rather than repeatedly for every script.

Doing this in every script is unnecessary since the event trigger is parameterized by the item id.
All that would happen is 2000 scripts would trigger 1999 unnecessary calls, and a large number of initialized scripts may eventually trigger a StackOverflowException.
Registration moved to UrlModule so that the handler is registered for all script engine implementations.
This required moving the OnScriptRemoved and OnObjectRemoved events (only used by UrlModule in core) from IScriptEngine to IScriptModule to avoid circular references.
0.7.2-post-fixes
Justin Clark-Casey (justincc) 2012-01-14 00:23:11 +00:00
parent b5971db76c
commit ab4c4a362f
4 changed files with 21 additions and 13 deletions

View File

@ -136,6 +136,12 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
public void RegionLoaded(Scene scene)
{
IScriptModule[] scriptModules = scene.RequestModuleInterfaces<IScriptModule>();
foreach (IScriptModule scriptModule in scriptModules)
{
scriptModule.OnScriptRemoved += ScriptRemoved;
scriptModule.OnObjectRemoved += ObjectRemoved;
}
}
public void RemoveRegion(Scene scene)
@ -166,7 +172,6 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
urlData.urlcode = urlcode;
urlData.requests = new Dictionary<UUID, RequestData>();
m_UrlMap[url] = urlData;
string uri = "/lslhttp/" + urlcode.ToString() + "/";
@ -281,6 +286,8 @@ namespace OpenSim.Region.CoreModules.Scripting.LSLHttp
public void ScriptRemoved(UUID itemID)
{
// m_log.DebugFormat("[URL MODULE]: Removing script {0}", itemID);
lock (m_UrlMap)
{
List<string> removeURLs = new List<string>();

View File

@ -31,8 +31,21 @@ using OpenMetaverse;
namespace OpenSim.Region.Framework.Interfaces
{
public delegate void ScriptRemoved(UUID script);
public delegate void ObjectRemoved(UUID prim);
public interface IScriptModule: INonSharedRegionModule
{
/// <summary>
/// Triggered when a script is removed from the script module.
/// </summary>
event ScriptRemoved OnScriptRemoved;
/// <summary>
/// Triggered when an object is removed via the script module.
/// </summary>
event ObjectRemoved OnObjectRemoved;
string ScriptEngineName { get; }
string GetXMLState(UUID itemID);

View File

@ -42,10 +42,6 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
/// An interface for a script API module to communicate with
/// the engine it's running under
/// </summary>
public delegate void ScriptRemoved(UUID script);
public delegate void ObjectRemoved(UUID prim);
public interface IScriptEngine
{
/// <summary>
@ -57,9 +53,6 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
IScriptModule ScriptModule { get; }
event ScriptRemoved OnScriptRemoved;
event ObjectRemoved OnObjectRemoved;
/// <summary>
/// Post an event to a single script
/// </summary>

View File

@ -126,11 +126,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_TransferModule =
m_ScriptEngine.World.RequestModuleInterface<IMessageTransferModule>();
m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
if (m_UrlModule != null)
{
m_ScriptEngine.OnScriptRemoved += m_UrlModule.ScriptRemoved;
m_ScriptEngine.OnObjectRemoved += m_UrlModule.ObjectRemoved;
}
AsyncCommands = new AsyncCommandManager(ScriptEngine);
}