diff options
author | Justin Clarke Casey | 2008-05-21 22:17:28 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-05-21 22:17:28 +0000 |
commit | 42ac35ba7d7c270da39a3f905c9bf18e6143807a (patch) | |
tree | 9ee399ba99166db8f3e9ca61e44e5b81920d2bae /OpenSim/Framework/PrimitiveBaseShape.cs | |
parent | * Going to the C# syntactic sugar way of handling the backup event delegates. (diff) | |
download | opensim-SC_OLD-42ac35ba7d7c270da39a3f905c9bf18e6143807a.zip opensim-SC_OLD-42ac35ba7d7c270da39a3f905c9bf18e6143807a.tar.gz opensim-SC_OLD-42ac35ba7d7c270da39a3f905c9bf18e6143807a.tar.bz2 opensim-SC_OLD-42ac35ba7d7c270da39a3f905c9bf18e6143807a.tar.xz |
* 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.
Diffstat (limited to 'OpenSim/Framework/PrimitiveBaseShape.cs')
-rw-r--r-- | OpenSim/Framework/PrimitiveBaseShape.cs | 72 |
1 files 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 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | ||
29 | using System.Xml.Serialization; | 30 | using System.Xml.Serialization; |
30 | using libsecondlife; | 31 | using libsecondlife; |
32 | using log4net; | ||
31 | 33 | ||
32 | namespace OpenSim.Framework | 34 | namespace OpenSim.Framework |
33 | { | 35 | { |
@@ -70,6 +72,8 @@ namespace OpenSim.Framework | |||
70 | [Serializable] | 72 | [Serializable] |
71 | public class PrimitiveBaseShape | 73 | public class PrimitiveBaseShape |
72 | { | 74 | { |
75 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
76 | |||
73 | private static readonly LLObject.TextureEntry m_defaultTexture; | 77 | private static readonly LLObject.TextureEntry m_defaultTexture; |
74 | 78 | ||
75 | private byte[] m_textureEntry; | 79 | private byte[] m_textureEntry; |
@@ -89,14 +93,53 @@ namespace OpenSim.Framework | |||
89 | public sbyte PathTwist; | 93 | public sbyte PathTwist; |
90 | public sbyte PathTwistBegin; | 94 | public sbyte PathTwistBegin; |
91 | public byte PCode; | 95 | public byte PCode; |
92 | public ushort ProfileBegin; | 96 | public ushort ProfileBegin; |
93 | 97 | ||
94 | public byte ProfileCurve; | 98 | public byte ProfileCurve |
99 | { | ||
100 | get { return (byte)((byte)HollowShape | (byte)ProfileShape); } | ||
101 | |||
102 | set | ||
103 | { | ||
104 | // Handle hollow shape component | ||
105 | byte hollowShapeByte = (byte)(value & 0xf0); | ||
106 | |||
107 | if (!Enum.IsDefined(typeof(HollowShape), hollowShapeByte)) | ||
108 | { | ||
109 | m_log.WarnFormat( | ||
110 | "[SHAPE]: Attempt to set a ProfileCurve with a hollow shape value of {0}, which isn't a valid enum. Replacing with default shape.", | ||
111 | hollowShapeByte); | ||
112 | |||
113 | this.HollowShape = HollowShape.Same; | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | this.HollowShape = (HollowShape)hollowShapeByte; | ||
118 | } | ||
119 | |||
120 | // Handle profile shape component | ||
121 | byte profileShapeByte = (byte)(value & 0xf); | ||
122 | |||
123 | if (!Enum.IsDefined(typeof(ProfileShape), profileShapeByte)) | ||
124 | { | ||
125 | m_log.WarnFormat( | ||
126 | "[SHAPE]: Attempt to set a ProfileCurve with a profile shape value of {0}, which isn't a valid enum. Replacing with square.", | ||
127 | profileShapeByte); | ||
128 | |||
129 | this.ProfileShape = ProfileShape.Square; | ||
130 | } | ||
131 | else | ||
132 | { | ||
133 | this.ProfileShape = (ProfileShape)profileShapeByte; | ||
134 | } | ||
135 | } | ||
136 | } | ||
95 | 137 | ||
96 | public ushort ProfileEnd; | 138 | public ushort ProfileEnd; |
97 | public ushort ProfileHollow; | 139 | public ushort ProfileHollow; |
98 | public LLVector3 Scale; | 140 | public LLVector3 Scale; |
99 | public byte State; | 141 | public byte State; |
142 | |||
100 | // Sculpted | 143 | // Sculpted |
101 | [XmlIgnore] public LLUUID SculptTexture = LLUUID.Zero; | 144 | [XmlIgnore] public LLUUID SculptTexture = LLUUID.Zero; |
102 | [XmlIgnore] public byte SculptType = (byte)0; | 145 | [XmlIgnore] public byte SculptType = (byte)0; |
@@ -154,25 +197,9 @@ namespace OpenSim.Framework | |||
154 | set { m_textureEntry = value; } | 197 | set { m_textureEntry = value; } |
155 | } | 198 | } |
156 | 199 | ||
157 | public ProfileShape ProfileShape | 200 | public ProfileShape ProfileShape; |
158 | { | 201 | |
159 | get { return (ProfileShape) (ProfileCurve & 0xf); } | 202 | public HollowShape HollowShape; |
160 | set | ||
161 | { | ||
162 | byte oldValueMasked = (byte) (ProfileCurve & 0xf0); | ||
163 | ProfileCurve = (byte) (oldValueMasked | (byte) value); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | public HollowShape HollowShape | ||
168 | { | ||
169 | get { return (HollowShape) (ProfileCurve & 0xf0); } | ||
170 | set | ||
171 | { | ||
172 | byte oldValueMasked = (byte) (ProfileCurve & 0x0f); | ||
173 | ProfileCurve = (byte) (oldValueMasked | (byte) value); | ||
174 | } | ||
175 | } | ||
176 | 203 | ||
177 | public static PrimitiveBaseShape Default | 204 | public static PrimitiveBaseShape Default |
178 | { | 205 | { |
@@ -186,7 +213,6 @@ namespace OpenSim.Framework | |||
186 | } | 213 | } |
187 | } | 214 | } |
188 | 215 | ||
189 | |||
190 | public static PrimitiveBaseShape Create() | 216 | public static PrimitiveBaseShape Create() |
191 | { | 217 | { |
192 | PrimitiveBaseShape shape = new PrimitiveBaseShape(); | 218 | PrimitiveBaseShape shape = new PrimitiveBaseShape(); |