Bug 112992

Summary: moving message widget in sequence diagram causes crash when other message is deleted
Product: [Applications] umbrello Reporter: Peter Soetens <peter.soetens>
Component: generalAssignee: Umbrello Development Group <umbrello-devel>
Status: RESOLVED FIXED    
Severity: crash    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: PATCH: correctly create and delete messages in sequence diagram
CLEANUP left-overs of previous patch

Description Peter Soetens 2005-09-21 11:00:09 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources
OS:                Linux

This may be related to other bugs, but the deletion of a message
of a sequence diagram is _very_ broken in current KDE 3.5 svn.
After delete, a move of remaining messages (on same object) will certainly crash.
I'll attach a patch, with more detailed info.
Comment 1 Peter Soetens 2005-09-21 11:05:53 UTC
Created attachment 12645 [details]
PATCH: correctly create and delete messages in sequence diagram

This bug was caused by
1. registering the message *twice* with the objects upon creation from toolbar
2. not checking for this in the registration functions, although relying on
correct use
3. not using the contract of an associationwidget correctly in the toolbar
widget. (activate() may *only* be called after serialisation, not after 'plain'
construction.

This patch fixes these three issues and maintains the contract.

NOTE to developers : this patch comments out the old code, you may remove the
commented parts all together before committing in svn.
Comment 2 Oliver Kellogg 2005-09-21 19:46:11 UTC
SVN commit 462673 by okellogg:

Patch from Peter Soetens <peter.soetens_AT_mech.kuleuven.be> fixes sequence
diagram message creation and deletion.
BUG:112992


 M  +1 -1      ChangeLog  
 M  +10 -6     umbrello/messagewidget.cpp  
 M  +12 -1     umbrello/objectwidget.cpp  
 M  +2 -1      umbrello/toolbarstatemessages.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #462672:462673
@@ -12,7 +12,7 @@
  57588  57672  58809  66461  67120  67719  72016  79433  87252  88117
  97162 105564 108223 109591 109636 110073 110216 110231 110379 111088
 111470 111502 111759 111768 112017 112292 112293 112333 112531 112552
-112936
+112936 112991 112992
 
 Version 1.4.2 (maintenance release)
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/messagewidget.cpp #462672:462673
@@ -43,17 +43,21 @@
         m_pOw[Uml::B]->setY(y);
     }
 
-    connect(m_pOw[Uml::A], SIGNAL(sigWidgetMoved(Uml::IDType)), this, SLOT(slotWidgetMoved(Uml::IDType)));
-    connect(m_pOw[Uml::B], SIGNAL(sigWidgetMoved(Uml::IDType)), this, SLOT(slotWidgetMoved(Uml::IDType)));
+    // This is done in activate()
+//     connect(m_pOw[Uml::A], SIGNAL(sigWidgetMoved(Uml::IDType)), this, SLOT(slotWidgetMoved(Uml::IDType)));
+//     connect(m_pOw[Uml::B], SIGNAL(sigWidgetMoved(Uml::IDType)), this, SLOT(slotWidgetMoved(Uml::IDType)));
     calculateWidget();
     y = y < getMinHeight() ? getMinHeight() : y;
     y = y > getMaxHeight() ? getMaxHeight() : y;
     m_nY = y;
 
-    connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::A], SLOT(slotMessageMoved()) );
-    connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::B], SLOT(slotMessageMoved()) );
-    m_pOw[Uml::A] -> messageAdded(this);
-    m_pOw[Uml::B] -> messageAdded(this);
+    // This is done in activate()
+//     connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::A], SLOT(slotMessageMoved()) );
+//     connect(this, SIGNAL(sigMessageMoved()), m_pOw[Uml::B], SLOT(slotMessageMoved()) );
+//     m_pOw[Uml::A] -> messageAdded(this);
+//     m_pOw[Uml::B] -> messageAdded(this);
+
+    this->activate();
 }
 
 MessageWidget::MessageWidget(UMLView * view, Uml::Sequence_Message_Type seqMsgType, Uml::IDType id)
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/objectwidget.cpp #462672:462673
@@ -322,11 +322,22 @@
 }
 
 void ObjectWidget::messageAdded(MessageWidget* message) {
+    if (messageWidgetList.containsRef(message) ) {
+        kdError() << "ObjectWidget::messageAdded("
+                  << message->getName() << ") : duplicate entry !"
+                  << endl;
+        return ;
+    }
     messageWidgetList.append(message);
 }
 
 void ObjectWidget::messageRemoved(MessageWidget* message) {
-    messageWidgetList.remove(message);
+    if ( messageWidgetList.remove(message) == false ) {
+        kdError() << "ObjectWidget::messageRemoved("
+                  << message->getName() << ") : missing entry !"
+                  << endl;
+        return ;
+    }
 }
 
 void ObjectWidget::slotMessageMoved() {
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/toolbarstatemessages.cpp #462672:462673
@@ -118,7 +118,8 @@
             m_pUMLView->connect(m_pUMLView, SIGNAL(sigColorChanged(Uml::IDType)),
                                 message, SLOT(slotColorChanged(Uml::IDType)));
 
-            message->activate();
+            // According to contract only call from serialisation _not_ when newly added to existing diagram.
+            //message->activate();
 
             m_pSelectedWidget = 0;
             m_pUMLView->getMessageList().append(message);
Comment 3 Peter Soetens 2005-09-22 08:49:20 UTC
Created attachment 12654 [details]
CLEANUP left-overs of previous patch

Apply this patch in addition to previous patch to remove the confusing
comments. Does not change code.