aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-09-12 21:05:26 +0100
committerJustin Clark-Casey (justincc)2011-09-12 21:05:26 +0100
commitdab6387bba7a7388e3cdb4ad1eeea646bc03a287 (patch)
tree1b41fb9d30fe422e73afa07695cd92d618a7770d /OpenSim/Framework
parentuncomment Standalone config in OpenSim.ini.example. (diff)
downloadopensim-SC_OLD-dab6387bba7a7388e3cdb4ad1eeea646bc03a287.zip
opensim-SC_OLD-dab6387bba7a7388e3cdb4ad1eeea646bc03a287.tar.gz
opensim-SC_OLD-dab6387bba7a7388e3cdb4ad1eeea646bc03a287.tar.bz2
opensim-SC_OLD-dab6387bba7a7388e3cdb4ad1eeea646bc03a287.tar.xz
lock AvatarAppearance.m_attachments when we use it
This is partly to address http://opensimulator.org/mantis/view.php?id=5644, though something more thorough is needed.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/AvatarAppearance.cs91
1 files changed, 58 insertions, 33 deletions
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index cce44b0..c69dde3 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -391,10 +391,14 @@ namespace OpenSim.Framework
391 public List<AvatarAttachment> GetAttachments() 391 public List<AvatarAttachment> GetAttachments()
392 { 392 {
393 List<AvatarAttachment> alist = new List<AvatarAttachment>(); 393 List<AvatarAttachment> alist = new List<AvatarAttachment>();
394 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments) 394
395 lock (m_attachments)
395 { 396 {
396 foreach (AvatarAttachment attach in kvp.Value) 397 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
397 alist.Add(new AvatarAttachment(attach)); 398 {
399 foreach (AvatarAttachment attach in kvp.Value)
400 alist.Add(new AvatarAttachment(attach));
401 }
398 } 402 }
399 403
400 return alist; 404 return alist;
@@ -406,10 +410,13 @@ namespace OpenSim.Framework
406// "[AVATAR APPEARNCE]: Appending itemID={0}, assetID={1} at {2}", 410// "[AVATAR APPEARNCE]: Appending itemID={0}, assetID={1} at {2}",
407// attach.ItemID, attach.AssetID, attach.AttachPoint); 411// attach.ItemID, attach.AssetID, attach.AttachPoint);
408 412
409 if (!m_attachments.ContainsKey(attach.AttachPoint)) 413 lock (m_attachments)
410 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>(); 414 {
411 415 if (!m_attachments.ContainsKey(attach.AttachPoint))
412 m_attachments[attach.AttachPoint].Add(attach); 416 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
417
418 m_attachments[attach.AttachPoint].Add(attach);
419 }
413 } 420 }
414 421
415 internal void ReplaceAttachment(AvatarAttachment attach) 422 internal void ReplaceAttachment(AvatarAttachment attach)
@@ -418,8 +425,11 @@ namespace OpenSim.Framework
418// "[AVATAR APPEARANCE]: Replacing itemID={0}, assetID={1} at {2}", 425// "[AVATAR APPEARANCE]: Replacing itemID={0}, assetID={1} at {2}",
419// attach.ItemID, attach.AssetID, attach.AttachPoint); 426// attach.ItemID, attach.AssetID, attach.AttachPoint);
420 427
421 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>(); 428 lock (m_attachments)
422 m_attachments[attach.AttachPoint].Add(attach); 429 {
430 m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
431 m_attachments[attach.AttachPoint].Add(attach);
432 }
423 } 433 }
424 434
425 /// <summary> 435 /// <summary>
@@ -448,10 +458,13 @@ namespace OpenSim.Framework
448 458
449 if (item == UUID.Zero) 459 if (item == UUID.Zero)
450 { 460 {
451 if (m_attachments.ContainsKey(attachpoint)) 461 lock (m_attachments)
452 { 462 {
453 m_attachments.Remove(attachpoint); 463 if (m_attachments.ContainsKey(attachpoint))
454 return true; 464 {
465 m_attachments.Remove(attachpoint);
466 return true;
467 }
455 } 468 }
456 469
457 return false; 470 return false;
@@ -494,11 +507,14 @@ namespace OpenSim.Framework
494 /// <returns>Returns null if this item is not attached.</returns> 507 /// <returns>Returns null if this item is not attached.</returns>
495 public AvatarAttachment GetAttachmentForItem(UUID itemID) 508 public AvatarAttachment GetAttachmentForItem(UUID itemID)
496 { 509 {
497 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments) 510 lock (m_attachments)
498 { 511 {
499 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; }); 512 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
500 if (index >= 0) 513 {
501 return kvp.Value[index]; 514 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
515 if (index >= 0)
516 return kvp.Value[index];
517 }
502 } 518 }
503 519
504 return null; 520 return null;
@@ -506,11 +522,14 @@ namespace OpenSim.Framework
506 522
507 public int GetAttachpoint(UUID itemID) 523 public int GetAttachpoint(UUID itemID)
508 { 524 {
509 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments) 525 lock (m_attachments)
510 { 526 {
511 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; }); 527 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
512 if (index >= 0) 528 {
513 return kvp.Key; 529 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
530 if (index >= 0)
531 return kvp.Key;
532 }
514 } 533 }
515 534
516 return 0; 535 return 0;
@@ -518,27 +537,32 @@ namespace OpenSim.Framework
518 537
519 public bool DetachAttachment(UUID itemID) 538 public bool DetachAttachment(UUID itemID)
520 { 539 {
521 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments) 540 lock (m_attachments)
522 { 541 {
523 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; }); 542 foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
524 if (index >= 0)
525 { 543 {
526 // Remove it from the list of attachments at that attach point 544 int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; });
527 m_attachments[kvp.Key].RemoveAt(index); 545 if (index >= 0)
528 546 {
529 // And remove the list if there are no more attachments here 547 // Remove it from the list of attachments at that attach point
530 if (m_attachments[kvp.Key].Count == 0) 548 m_attachments[kvp.Key].RemoveAt(index);
531 m_attachments.Remove(kvp.Key); 549
532 550 // And remove the list if there are no more attachments here
533 return true; 551 if (m_attachments[kvp.Key].Count == 0)
552 m_attachments.Remove(kvp.Key);
553
554 return true;
555 }
534 } 556 }
535 } 557 }
558
536 return false; 559 return false;
537 } 560 }
538 561
539 public void ClearAttachments() 562 public void ClearAttachments()
540 { 563 {
541 m_attachments.Clear(); 564 lock (m_attachments)
565 m_attachments.Clear();
542 } 566 }
543 567
544 #region Packing Functions 568 #region Packing Functions
@@ -576,7 +600,8 @@ namespace OpenSim.Framework
576 data["visualparams"] = visualparams; 600 data["visualparams"] = visualparams;
577 601
578 // Attachments 602 // Attachments
579 OSDArray attachs = new OSDArray(m_attachments.Count); 603 List<AvatarAttachment> attachments = GetAttachments();
604 OSDArray attachs = new OSDArray(attachments.Count);
580 foreach (AvatarAttachment attach in GetAttachments()) 605 foreach (AvatarAttachment attach in GetAttachments())
581 attachs.Add(attach.Pack()); 606 attachs.Add(attach.Pack());
582 data["attachments"] = attachs; 607 data["attachments"] = attachs;