From b4dcdffb5094c488a98acbe675b333c3bd4cc570 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 16 Mar 2010 11:50:22 -0700 Subject: Fixed several unhandled exceptions and performance issues with PrimitiveBaseShape.Textures. This really should be moved from a property to a method if it is going to decode a byte[] into a TextureEntry each time --- OpenSim/Framework/PrimitiveBaseShape.cs | 8 ++- .../DynamicTexture/DynamicTextureModule.cs | 20 ++++--- .../CoreModules/World/WorldMap/MapImageModule.cs | 7 ++- OpenSim/Region/DataSnapshot/ObjectSnapshot.cs | 62 +++++++++++++--------- OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 23 ++++---- 5 files changed, 66 insertions(+), 54 deletions(-) diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index 6a38278..9c2a4f9 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -227,8 +227,12 @@ namespace OpenSim.Framework { get { - //m_log.DebugFormat("[PRIMITIVE BASE SHAPE]: get m_textureEntry length {0}", m_textureEntry.Length); - return new Primitive.TextureEntry(m_textureEntry, 0, m_textureEntry.Length); + //m_log.DebugFormat("[SHAPE]: get m_textureEntry length {0}", m_textureEntry.Length); + try { return new Primitive.TextureEntry(m_textureEntry, 0, m_textureEntry.Length); } + catch { } + + m_log.Warn("[SHAPE]: Failed to decode texture, length=" + ((m_textureEntry != null) ? m_textureEntry.Length : 0)); + return new Primitive.TextureEntry(null); } set { m_textureEntry = value.GetBytes(); } diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index 643764f..678e772 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs @@ -285,24 +285,22 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture return; } - byte[] assetData; + byte[] assetData = null; AssetBase oldAsset = null; if (BlendWithOldTexture) { - UUID lastTextureID = part.Shape.Textures.DefaultTexture.TextureID; - oldAsset = scene.AssetService.Get(lastTextureID.ToString()); - if (oldAsset != null) - { - assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha); - } - else + Primitive.TextureEntryFace defaultFace = part.Shape.Textures.DefaultTexture; + if (defaultFace != null) { - assetData = new byte[data.Length]; - Array.Copy(data, assetData, data.Length); + oldAsset = scene.AssetService.Get(defaultFace.TextureID.ToString()); + + if (oldAsset != null) + assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha); } } - else + + if (assetData == null) { assetData = new byte[data.Length]; Array.Copy(data, assetData, data.Length); diff --git a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs index 285d36a..b71b5f6 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/MapImageModule.cs @@ -251,13 +251,12 @@ namespace OpenSim.Region.CoreModules.World.WorldMap // if you want tree blocks on the map comment the above line and uncomment the below line //mapdotspot = Color.PaleGreen; - if (part.Shape.Textures == null) - continue; + Primitive.TextureEntry textureEntry = part.Shape.Textures; - if (part.Shape.Textures.DefaultTexture == null) + if (textureEntry == null || textureEntry.DefaultTexture == null) continue; - Color4 texcolor = part.Shape.Textures.DefaultTexture.RGBA; + Color4 texcolor = textureEntry.DefaultTexture.RGBA; // Not sure why some of these are null, oh well. diff --git a/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs b/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs index 76dac61..f441aa9 100644 --- a/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs +++ b/OpenSim/Region/DataSnapshot/ObjectSnapshot.cs @@ -203,44 +203,54 @@ namespace OpenSim.Region.DataSnapshot.Providers { string bestguess = string.Empty; Dictionary counts = new Dictionary(); - if (sog.RootPart.Shape != null && sog.RootPart.Shape.ProfileShape == ProfileShape.Square && - sog.RootPart.Shape.Textures != null && sog.RootPart.Shape.Textures.FaceTextures != null) + + PrimitiveBaseShape shape = sog.RootPart.Shape; + if (shape != null && shape.ProfileShape == ProfileShape.Square) { - if (sog.RootPart.Shape.Textures.DefaultTexture.TextureID != UUID.Zero && - sog.RootPart.Shape.Textures.DefaultTexture.TextureID != m_DefaultImage && - sog.RootPart.Shape.Textures.DefaultTexture.TextureID != m_BlankImage && - sog.RootPart.Shape.Textures.DefaultTexture.RGBA.A < 50) + Primitive.TextureEntry textures = shape.Textures; + if (textures != null) { - counts[sog.RootPart.Shape.Textures.DefaultTexture.TextureID] = 8; - } + if (textures.DefaultTexture != null && + textures.DefaultTexture.TextureID != UUID.Zero && + textures.DefaultTexture.TextureID != m_DefaultImage && + textures.DefaultTexture.TextureID != m_BlankImage && + textures.DefaultTexture.RGBA.A < 50f) + { + counts[textures.DefaultTexture.TextureID] = 8; + } - foreach (Primitive.TextureEntryFace tentry in sog.RootPart.Shape.Textures.FaceTextures) - { - if (tentry != null) + if (textures.FaceTextures != null) { - if (tentry.TextureID != UUID.Zero && tentry.TextureID != m_DefaultImage && tentry.TextureID != m_BlankImage && tentry.RGBA.A < 50) + foreach (Primitive.TextureEntryFace tentry in textures.FaceTextures) { - int c = 0; - counts.TryGetValue(tentry.TextureID, out c); - counts[tentry.TextureID] = c + 1; - // decrease the default texture count - if (counts.ContainsKey(sog.RootPart.Shape.Textures.DefaultTexture.TextureID)) - counts[sog.RootPart.Shape.Textures.DefaultTexture.TextureID] = counts[sog.RootPart.Shape.Textures.DefaultTexture.TextureID] - 1; + if (tentry != null) + { + if (tentry.TextureID != UUID.Zero && tentry.TextureID != m_DefaultImage && tentry.TextureID != m_BlankImage && tentry.RGBA.A < 50) + { + int c = 0; + counts.TryGetValue(tentry.TextureID, out c); + counts[tentry.TextureID] = c + 1; + // decrease the default texture count + if (counts.ContainsKey(textures.DefaultTexture.TextureID)) + counts[textures.DefaultTexture.TextureID] = counts[textures.DefaultTexture.TextureID] - 1; + } + } } } - } - // Let's pick the most unique texture - int min = 9999; - foreach (KeyValuePair kv in counts) - { - if (kv.Value < min && kv.Value >= 1) + // Let's pick the most unique texture + int min = 9999; + foreach (KeyValuePair kv in counts) { - bestguess = kv.Key.ToString(); - min = kv.Value; + if (kv.Value < min && kv.Value >= 1) + { + bestguess = kv.Key.ToString(); + min = kv.Value; + } } } } + return bestguess; } } diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 4a1f648..0ec3cc3 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -129,19 +129,20 @@ namespace OpenSim.Region.Framework.Scenes try { Primitive.TextureEntry textureEntry = part.Shape.Textures; - - // Get the prim's default texture. This will be used for faces which don't have their own texture - assetUuids[textureEntry.DefaultTexture.TextureID] = AssetType.Texture; - - // XXX: Not a great way to iterate through face textures, but there's no - // other method available to tell how many faces there actually are - //int i = 0; - foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) + if (textureEntry != null) { - if (texture != null) + // Get the prim's default texture. This will be used for faces which don't have their own texture + if (textureEntry.DefaultTexture != null) + assetUuids[textureEntry.DefaultTexture.TextureID] = AssetType.Texture; + + if (textureEntry.FaceTextures != null) { - //m_log.DebugFormat("[ARCHIVER]: Got face {0}", i++); - assetUuids[texture.TextureID] = AssetType.Texture; + // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture) + foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) + { + if (texture != null) + assetUuids[texture.TextureID] = AssetType.Texture; + } } } -- cgit v1.1