From 42ac35ba7d7c270da39a3f905c9bf18e6143807a Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Wed, 21 May 2008 22:17:28 +0000 Subject: * Provide relief for mantis 1263, 1202, 679 * If a caller attempts to set PrimitiveBaseShape.ProfileCurve with a HollowShape or ProfileShape component which is not a valid enum, a warning is spat out and a default shape subtituted * This does not solve any underlying problem if we're missing some enum values (though it's not obvious what these are), but it should allow save-xml2/load-xml2 to be used without causing invalid enum value related exceptions. The checks will also guard against badly behaved clients. * This change alters the order of shape values in the xml, since it appears properties are serialized after fields (at least this is the case in mono). .net native deserialization can cope with this it appears, though people manipulating xml manually may need to adapt (if there are any). * This may be a good argument against relying on .net [de]serialization for our xml format. --- OpenSim/Framework/PrimitiveBaseShape.cs | 72 ++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index f03c6d0..23969fe 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -26,8 +26,10 @@ */ using System; +using System.Reflection; using System.Xml.Serialization; using libsecondlife; +using log4net; namespace OpenSim.Framework { @@ -70,6 +72,8 @@ namespace OpenSim.Framework [Serializable] public class PrimitiveBaseShape { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly LLObject.TextureEntry m_defaultTexture; private byte[] m_textureEntry; @@ -89,14 +93,53 @@ namespace OpenSim.Framework public sbyte PathTwist; public sbyte PathTwistBegin; public byte PCode; - public ushort ProfileBegin; - - public byte ProfileCurve; + public ushort ProfileBegin; + + public byte ProfileCurve + { + get { return (byte)((byte)HollowShape | (byte)ProfileShape); } + + set + { + // Handle hollow shape component + byte hollowShapeByte = (byte)(value & 0xf0); + + if (!Enum.IsDefined(typeof(HollowShape), hollowShapeByte)) + { + m_log.WarnFormat( + "[SHAPE]: Attempt to set a ProfileCurve with a hollow shape value of {0}, which isn't a valid enum. Replacing with default shape.", + hollowShapeByte); + + this.HollowShape = HollowShape.Same; + } + else + { + this.HollowShape = (HollowShape)hollowShapeByte; + } + + // Handle profile shape component + byte profileShapeByte = (byte)(value & 0xf); + + if (!Enum.IsDefined(typeof(ProfileShape), profileShapeByte)) + { + m_log.WarnFormat( + "[SHAPE]: Attempt to set a ProfileCurve with a profile shape value of {0}, which isn't a valid enum. Replacing with square.", + profileShapeByte); + + this.ProfileShape = ProfileShape.Square; + } + else + { + this.ProfileShape = (ProfileShape)profileShapeByte; + } + } + } public ushort ProfileEnd; public ushort ProfileHollow; public LLVector3 Scale; public byte State; + // Sculpted [XmlIgnore] public LLUUID SculptTexture = LLUUID.Zero; [XmlIgnore] public byte SculptType = (byte)0; @@ -154,25 +197,9 @@ namespace OpenSim.Framework set { m_textureEntry = value; } } - public ProfileShape ProfileShape - { - get { return (ProfileShape) (ProfileCurve & 0xf); } - set - { - byte oldValueMasked = (byte) (ProfileCurve & 0xf0); - ProfileCurve = (byte) (oldValueMasked | (byte) value); - } - } - - public HollowShape HollowShape - { - get { return (HollowShape) (ProfileCurve & 0xf0); } - set - { - byte oldValueMasked = (byte) (ProfileCurve & 0x0f); - ProfileCurve = (byte) (oldValueMasked | (byte) value); - } - } + public ProfileShape ProfileShape; + + public HollowShape HollowShape; public static PrimitiveBaseShape Default { @@ -186,7 +213,6 @@ namespace OpenSim.Framework } } - public static PrimitiveBaseShape Create() { PrimitiveBaseShape shape = new PrimitiveBaseShape(); -- cgit v1.1