Browse Source

*** empty log message ***

David Rose 25 năm trước cách đây
mục cha
commit
afb1ea3200
1 tập tin đã thay đổi với 19 bổ sung6 xóa
  1. 19 6
      panda/src/graph/arcChain.cxx

+ 19 - 6
panda/src/graph/arcChain.cxx

@@ -14,19 +14,32 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void ArcChain::ArcComponent::
 void ArcChain::ArcComponent::
 operator = (const ArcComponent &copy) {
 operator = (const ArcComponent &copy) {
-  _next = copy._next;
+  // We have to be careful with the reference counts here,
+  // particularly since we might be changing the pointer type from arc
+  // pointer to node pointer, or vice-versa, with this assignment.
 
 
-  if (has_arc()) {
-    // Ref the new one before unreffing the old one, so we don't
-    // accidentally delete in the interim.
+  // First, ref the new pointer once, so we don't accidentally delete
+  // in the interim.
+  if (copy.has_arc()) {
     copy._p._arc->ref();
     copy._p._arc->ref();
     copy._p._arc->ref_parent();
     copy._p._arc->ref_parent();
+  } else {
+    copy._p._node->ref();
+  }
+
+  // Now unref the old pointer.
+  if (has_arc()) {
     _p._arc->unref_parent();
     _p._arc->unref_parent();
     unref_delete(_p._arc);
     unref_delete(_p._arc);
-    _p._arc = copy._p._arc;
   } else {
   } else {
-    copy._p._node->ref();
     unref_delete(_p._node);
     unref_delete(_p._node);
+  }
+
+  // Now reassign the pointers.
+  _next = copy._next;
+  if (has_arc()) {
+    _p._arc = copy._p._arc;
+  } else {
     _p._node = copy._p._node;
     _p._node = copy._p._node;
   }
   }
 }
 }