aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
authorOren Hurvitz2014-06-01 17:39:11 +0300
committerJustin Clark-Casey2014-08-02 00:55:57 +0100
commite41e52e09727842d990a31e2a5f7f3e9c88fe8b3 (patch)
tree5779c9f42cd913f63e2d237b5a407214933585db /OpenSim/Region/Framework
parentAdd code to GridService to check for overlapping of varregions (diff)
downloadopensim-SC_OLD-e41e52e09727842d990a31e2a5f7f3e9c88fe8b3.zip
opensim-SC_OLD-e41e52e09727842d990a31e2a5f7f3e9c88fe8b3.tar.gz
opensim-SC_OLD-e41e52e09727842d990a31e2a5f7f3e9c88fe8b3.tar.bz2
opensim-SC_OLD-e41e52e09727842d990a31e2a5f7f3e9c88fe8b3.tar.xz
Close streams immediately when we finish using them
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs49
-rw-r--r--OpenSim/Region/Framework/Scenes/KeyframeMotion.cs46
-rw-r--r--OpenSim/Region/Framework/Scenes/UuidGatherer.cs57
3 files changed, 80 insertions, 72 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs b/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs
index 3afc87f..b3b38b2 100644
--- a/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs
+++ b/OpenSim/Region/Framework/Scenes/Animation/BinBVHAnimation.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -113,31 +113,34 @@ namespace OpenSim.Region.Framework.Scenes.Animation
113 113
114 public byte[] ToBytes() 114 public byte[] ToBytes()
115 { 115 {
116 byte[] outputbytes = new byte[0]; 116 byte[] outputbytes;
117 117
118 BinaryWriter iostream = new BinaryWriter(new MemoryStream()); 118 using (MemoryStream ms = new MemoryStream())
119 iostream.Write(BinBVHUtil.ES(Utils.UInt16ToBytes(unknown0))); 119 using (BinaryWriter iostream = new BinaryWriter(ms))
120 iostream.Write(BinBVHUtil.ES(Utils.UInt16ToBytes(unknown1)));
121 iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(Priority)));
122 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(Length)));
123 iostream.Write(BinBVHUtil.WriteNullTerminatedString(ExpressionName));
124 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(InPoint)));
125 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(OutPoint)));
126 iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(Loop ? 1 : 0)));
127 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(EaseInTime)));
128 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(EaseOutTime)));
129 iostream.Write(BinBVHUtil.ES(Utils.UIntToBytes(HandPose)));
130 iostream.Write(BinBVHUtil.ES(Utils.UIntToBytes((uint)(Joints.Length))));
131
132 for (int i = 0; i < Joints.Length; i++)
133 { 120 {
134 Joints[i].WriteBytesToStream(iostream, InPoint, OutPoint); 121 iostream.Write(BinBVHUtil.ES(Utils.UInt16ToBytes(unknown0)));
122 iostream.Write(BinBVHUtil.ES(Utils.UInt16ToBytes(unknown1)));
123 iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(Priority)));
124 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(Length)));
125 iostream.Write(BinBVHUtil.WriteNullTerminatedString(ExpressionName));
126 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(InPoint)));
127 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(OutPoint)));
128 iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(Loop ? 1 : 0)));
129 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(EaseInTime)));
130 iostream.Write(BinBVHUtil.ES(Utils.FloatToBytes(EaseOutTime)));
131 iostream.Write(BinBVHUtil.ES(Utils.UIntToBytes(HandPose)));
132 iostream.Write(BinBVHUtil.ES(Utils.UIntToBytes((uint)(Joints.Length))));
133
134 for (int i = 0; i < Joints.Length; i++)
135 {
136 Joints[i].WriteBytesToStream(iostream, InPoint, OutPoint);
137 }
138 iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(0)));
139
140 using (MemoryStream ms2 = (MemoryStream)iostream.BaseStream)
141 outputbytes = ms2.ToArray();
135 } 142 }
136 iostream.Write(BinBVHUtil.ES(Utils.IntToBytes(0))); 143
137 MemoryStream ms = (MemoryStream)iostream.BaseStream;
138 outputbytes = ms.ToArray();
139 ms.Close();
140 iostream.Close();
141 return outputbytes; 144 return outputbytes;
142 } 145 }
143 146
diff --git a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
index 2d489ea..b4a171f 100644
--- a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
+++ b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs
@@ -280,7 +280,7 @@ namespace OpenSim.Region.Framework.Scenes
280 if (!m_selected) 280 if (!m_selected)
281 { 281 {
282 StopTimer(); 282 StopTimer();
283 m_serializedPosition = m_group.AbsolutePosition; 283 m_serializedPosition = m_group.AbsolutePosition;
284 } 284 }
285 } 285 }
286 } 286 }
@@ -308,10 +308,11 @@ namespace OpenSim.Region.Framework.Scenes
308 308
309 try 309 try
310 { 310 {
311 MemoryStream ms = new MemoryStream(data); 311 using (MemoryStream ms = new MemoryStream(data))
312 BinaryFormatter fmt = new BinaryFormatter(); 312 {
313 313 BinaryFormatter fmt = new BinaryFormatter();
314 newMotion = (KeyframeMotion)fmt.Deserialize(ms); 314 newMotion = (KeyframeMotion)fmt.Deserialize(ms);
315 }
315 316
316 newMotion.m_group = grp; 317 newMotion.m_group = grp;
317 318
@@ -345,26 +346,26 @@ namespace OpenSim.Region.Framework.Scenes
345 return; 346 return;
346 347
347 m_group = grp; 348 m_group = grp;
348 m_scene = grp.Scene; 349 m_scene = grp.Scene;
349 350
350 Vector3 grppos = grp.AbsolutePosition; 351 Vector3 grppos = grp.AbsolutePosition;
351 Vector3 offset = grppos - m_serializedPosition; 352 Vector3 offset = grppos - m_serializedPosition;
352 // avoid doing it more than once 353 // avoid doing it more than once
353 // current this will happen dragging a prim to other region 354 // current this will happen dragging a prim to other region
354 m_serializedPosition = grppos; 355 m_serializedPosition = grppos;
355 356
356 m_basePosition += offset; 357 m_basePosition += offset;
357 m_nextPosition += offset; 358 m_nextPosition += offset;
358 359
359 m_currentFrame.StartPosition += offset; 360 m_currentFrame.StartPosition += offset;
360 m_currentFrame.Position += offset; 361 m_currentFrame.Position += offset;
361 362
362 for (int i = 0; i < m_frames.Count; i++) 363 for (int i = 0; i < m_frames.Count; i++)
363 { 364 {
364 Keyframe k = m_frames[i]; 365 Keyframe k = m_frames[i];
365 k.StartPosition += offset; 366 k.StartPosition += offset;
366 k.Position += offset; 367 k.Position += offset;
367 m_frames[i]=k; 368 m_frames[i]=k;
368 } 369 }
369 370
370 if (m_running) 371 if (m_running)
@@ -527,7 +528,7 @@ namespace OpenSim.Region.Framework.Scenes
527 { 528 {
528 k.Position = pos; 529 k.Position = pos;
529// k.Velocity = Vector3.Zero; 530// k.Velocity = Vector3.Zero;
530 } 531 }
531 532
532 k.StartRotation = rot; 533 k.StartRotation = rot;
533 if (k.Rotation.HasValue) 534 if (k.Rotation.HasValue)
@@ -764,19 +765,22 @@ namespace OpenSim.Region.Framework.Scenes
764 public Byte[] Serialize() 765 public Byte[] Serialize()
765 { 766 {
766 StopTimer(); 767 StopTimer();
767 MemoryStream ms = new MemoryStream();
768 768
769 BinaryFormatter fmt = new BinaryFormatter();
770 SceneObjectGroup tmp = m_group; 769 SceneObjectGroup tmp = m_group;
771 m_group = null; 770 m_group = null;
772 if (!m_selected && tmp != null) 771 if (!m_selected && tmp != null)
773 m_serializedPosition = tmp.AbsolutePosition; 772 m_serializedPosition = tmp.AbsolutePosition;
774 fmt.Serialize(ms, this); 773
775 m_group = tmp; 774 using (MemoryStream ms = new MemoryStream())
776 if (m_running && !m_waitingCrossing) 775 {
777 StartTimer(); 776 BinaryFormatter fmt = new BinaryFormatter();
777 fmt.Serialize(ms, this);
778 m_group = tmp;
779 if (m_running && !m_waitingCrossing)
780 StartTimer();
778 781
779 return ms.ToArray(); 782 return ms.ToArray();
783 }
780 } 784 }
781 785
782 public void StartCrossingCheck() 786 public void StartCrossingCheck()
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
index a7015e1..d07cc6a 100644
--- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
+++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs
@@ -458,35 +458,36 @@ namespace OpenSim.Region.Framework.Scenes
458 if (null == assetBase) 458 if (null == assetBase)
459 return; 459 return;
460 460
461 MemoryStream ms = new MemoryStream(assetBase.Data); 461 using (MemoryStream ms = new MemoryStream(assetBase.Data))
462 StreamReader sr = new StreamReader(ms); 462 using (StreamReader sr = new StreamReader(ms))
463
464 sr.ReadLine(); // Unknown (Version?)
465 sr.ReadLine(); // Unknown
466 sr.ReadLine(); // Unknown
467 sr.ReadLine(); // Name
468 sr.ReadLine(); // Comment ?
469 int count = Convert.ToInt32(sr.ReadLine()); // Item count
470
471 for (int i = 0 ; i < count ; i++)
472 { 463 {
473 string type = sr.ReadLine(); 464 sr.ReadLine(); // Unknown (Version?)
474 if (type == null) 465 sr.ReadLine(); // Unknown
475 break; 466 sr.ReadLine(); // Unknown
476 string name = sr.ReadLine(); 467 sr.ReadLine(); // Name
477 if (name == null) 468 sr.ReadLine(); // Comment ?
478 break; 469 int count = Convert.ToInt32(sr.ReadLine()); // Item count
479 string id = sr.ReadLine(); 470
480 if (id == null) 471 for (int i = 0 ; i < count ; i++)
481 break; 472 {
482 string unknown = sr.ReadLine(); 473 string type = sr.ReadLine();
483 if (unknown == null) 474 if (type == null)
484 break; 475 break;
485 476 string name = sr.ReadLine();
486 // If it can be parsed as a UUID, it is an asset ID 477 if (name == null)
487 UUID uuid; 478 break;
488 if (UUID.TryParse(id, out uuid)) 479 string id = sr.ReadLine();
489 assetUuids[uuid] = (sbyte)AssetType.Animation; 480 if (id == null)
481 break;
482 string unknown = sr.ReadLine();
483 if (unknown == null)
484 break;
485
486 // If it can be parsed as a UUID, it is an asset ID
487 UUID uuid;
488 if (UUID.TryParse(id, out uuid))
489 assetUuids[uuid] = (sbyte)AssetType.Animation; // the asset is either an Animation or a Sound, but this distinction isn't important
490 }
490 } 491 }
491 } 492 }
492 493