From d89b974680af52a2d950237962240dde82ff4a85 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 30 Aug 2012 22:28:45 +0100 Subject: If the compile-time DynamicTextureModule.ReuseTextures flag is set, check metadata still exists for any reused asset in case some other process has removed it from the cache. --- .../DynamicTexture/DynamicTextureModule.cs | 102 ++++++++++++--------- 1 file changed, 59 insertions(+), 43 deletions(-) (limited to 'OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs') diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index 13b7498..f169117 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs @@ -186,63 +186,79 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, string extraParams, int updateTimer, bool SetBlending, int disp, byte AlphaValue, int face) { - if (RenderPlugins.ContainsKey(contentType)) - { - // If we want to reuse dynamic textures then we have to ignore any request from the caller to expire - // them. - if (ReuseTextures) - disp = disp & ~DISP_EXPIRE; + if (!RenderPlugins.ContainsKey(contentType)) + return UUID.Zero; - DynamicTextureUpdater updater = new DynamicTextureUpdater(); - updater.SimUUID = simID; - updater.PrimID = primID; - updater.ContentType = contentType; - updater.BodyData = data; - updater.UpdateTimer = updateTimer; - updater.UpdaterID = UUID.Random(); - updater.Params = extraParams; - updater.BlendWithOldTexture = SetBlending; - updater.FrontAlpha = AlphaValue; - updater.Face = face; - updater.Url = "Local image"; - updater.Disp = disp; + Scene scene; + RegisteredScenes.TryGetValue(simID, out scene); + + if (scene == null) + return UUID.Zero; - object reusableTextureUUID = null; + SceneObjectPart part = scene.GetSceneObjectPart(primID); - if (ReuseTextures) - reusableTextureUUID - = m_reuseableDynamicTextures.Get(GenerateReusableTextureKey(data, extraParams)); + if (part == null) + return UUID.Zero; + + // If we want to reuse dynamic textures then we have to ignore any request from the caller to expire + // them. + if (ReuseTextures) + disp = disp & ~DISP_EXPIRE; + + DynamicTextureUpdater updater = new DynamicTextureUpdater(); + updater.SimUUID = simID; + updater.PrimID = primID; + updater.ContentType = contentType; + updater.BodyData = data; + updater.UpdateTimer = updateTimer; + updater.UpdaterID = UUID.Random(); + updater.Params = extraParams; + updater.BlendWithOldTexture = SetBlending; + updater.FrontAlpha = AlphaValue; + updater.Face = face; + updater.Url = "Local image"; + updater.Disp = disp; + + object objReusableTextureUUID = null; + + if (ReuseTextures && !updater.BlendWithOldTexture) + { + string reuseableTextureKey = GenerateReusableTextureKey(data, extraParams); + objReusableTextureUUID = m_reuseableDynamicTextures.Get(reuseableTextureKey); - // We cannot reuse a dynamic texture if the data is going to be blended with something already there. - if (reusableTextureUUID == null || updater.BlendWithOldTexture) + if (objReusableTextureUUID != null) { - lock (Updaters) + // If something else has removed this temporary asset from the cache, detect and invalidate + // our cached uuid. + if (scene.AssetService.GetMetadata(objReusableTextureUUID.ToString()) == null) { - if (!Updaters.ContainsKey(updater.UpdaterID)) - { - Updaters.Add(updater.UpdaterID, updater); - } + m_reuseableDynamicTextures.Invalidate(reuseableTextureKey); + objReusableTextureUUID = null; } - - RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams); } - else + } + + // We cannot reuse a dynamic texture if the data is going to be blended with something already there. + if (objReusableTextureUUID == null) + { + lock (Updaters) { - // No need to add to updaters as the texture is always the same. Not that this functionality - // apppears to be implemented anyway. - if (RegisteredScenes.ContainsKey(updater.SimUUID)) + if (!Updaters.ContainsKey(updater.UpdaterID)) { - SceneObjectPart part = RegisteredScenes[updater.SimUUID].GetSceneObjectPart(updater.PrimID); - - if (part != null) - updater.UpdatePart(part, (UUID)reusableTextureUUID); + Updaters.Add(updater.UpdaterID, updater); } } - return updater.UpdaterID; + RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams); } - - return UUID.Zero; + else + { + // No need to add to updaters as the texture is always the same. Not that this functionality + // apppears to be implemented anyway. + updater.UpdatePart(part, (UUID)objReusableTextureUUID); + } + + return updater.UpdaterID; } private string GenerateReusableTextureKey(string data, string extraParams) -- cgit v1.1