[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    [PATCH] Fix crash in K3ListView
From:       Christoph Feck <christoph () maxiom ! de>
Date:       2008-12-17 15:26:49
Message-ID: 200812171626.50102.christoph () maxiom ! de
[Download RAW message or body]

Hello all,

Richard "nixternal" Johnson of Kubuntu fame reported a crash in Qt Designer
when using Skulpture style. Debugging this, I found out that there are 
actually two crashes: one has been fixed in Skulpture, the other is explained 
below.

Since Designer is not a KDE application, I had to use gdb to get a backtrace.
The following trace is presented in call order (a forwardtrace?) and 
annotated.

Follow carefully, you got to learn something new ;)

#16 0xb7b1fb95 in qdesigner_internal::WidgetFactory::createCustomWidget 
(this=0x81844f0, className=@0xbfc6d764, parentWidget=0x0, 
creationError=0xbfc6d6ab)
    Designer loaded its plugins and now creates the widgets

#15 0xb61f2934 in K3ListViewPlugin::createWidget () 
from /mnt/local/kde4/lib/kde4/plugins/designer/kde3supportwidgets.so
#14 0xb549059b in K3ListView::K3ListView () 
from /usr/local/kde4/lib/libkde3support.so.4
    A KDE 3 Support widget is created (K3ListView)

#13 0xb548d904 in K3ListViewLineEdit::K3ListViewLineEdit () 
from /usr/local/kde4/lib/libkde3support.so.4
#12 0xb5deeff9 in KLineEdit::KLineEdit () 
from /usr/local/kde4/lib/libkdeui.so.5
#11 0xb5de8203 in KLineEdit::init () from /usr/local/kde4/lib/libkdeui.so.5
   That listview creates a lineedit widget (in its d-pointer constructor!)

#10 0xb5d45f27 in KGlobalSettings::self () 
from /usr/local/kde4/lib/libkdeui.so.5
#9  0xb5d45c9b in KGlobalSettings::KGlobalSettings () 
from /usr/local/kde4/lib/libkdeui.so.5
#8  0xb5d42e4e in KGlobalSettings::Private::kdisplaySetStyle () 
from /usr/local/kde4/lib/libkdeui.so.5
    The lineedit appearently needs KDE settings and calls into KGlobalSettings

#7  0xb5d42d9c in KGlobalSettings::Private::kdisplaySetPalette () 
from /usr/local/kde4/lib/libkdeui.so.5
    That in turn makes KDE initialize its palette

#6  0xb6e87a7c in QApplication::setPalette (palette=@0xbfc6d340, 
className=0x0) at /mnt/git/qt-snapshot/src/gui/kernel/qapplication.cpp:1750
#5  0xb6e87763 in QApplicationPrivate::setPalette_helper (palette=@0xbfc6d340, 
className=0x0, clearWidgetPaletteHash=true)
at ../../include/QtCore/../../../../git/qt-snapshot/src/corelib/kernel/qcoreapplication.h:208
#4  0xb68ca79b in QCoreApplication::notifyInternal (this=0xbfc6d984, 
receiver=0x84139a8, event=0xbfc6d2dc) 
at /mnt/git/qt-snapshot/src/corelib/kernel/qcoreapplication.cpp:590
#3  0xb6e8bd3a in QApplication::notify (this=0xbfc6d984, receiver=0x84139a8, 
e=0xbfc6d2dc) at /mnt/git/qt-snapshot/src/gui/kernel/qapplication.cpp:3944
#2  0xb6e83c1c in QApplicationPrivate::notify_helper (this=0x80bb660, 
receiver=0xbfc6d2dc, e=0xbfc6cfbc) 
at /mnt/git/qt-snapshot/src/gui/kernel/qapplication.cpp:3979
    Creating that palette notifies the application about the palette change

#1  0xb548cb13 in K3ListView::event () 
from /usr/local/kde4/lib/libkde3support.so.4
    Eventually, the K3ListView gets the QEvent::ApplicationPaletteChange event
    (before it its constructor has finished!)

#0  0xb6f835db in QColor::operator= (this=0xac, color=@0x8435d98) 
at /mnt/git/qt-snapshot/src/gui/painting/qcolor.cpp:1908
    ... and crashes because it stores a color to nowhere.

Why? Because the d-pointer of the K3ListView is currently being created,
but its value is not set yet, because it is still in executing the constructor 
of the d-pointer member!

So what should we learn? Never create widgets inside the constructor of
a widget before the d-pointer has been assigned.

Attached is a patch for kdelibs/kde3support, please review.
Maybe we need an EBN checker for this type of error?

Christoph (kdepepo)

["kde3support.diff" (text/x-diff)]

Index: kdeui/k3listview.cpp
===================================================================
--- kdeui/k3listview.cpp	(Revision 898052)
+++ kdeui/k3listview.cpp	(Arbeitskopie)
@@ -74,12 +74,12 @@
 class K3ListView::K3ListViewPrivate
 {
 public:
-  K3ListViewPrivate (K3ListView* listview)
+  K3ListViewPrivate ()
     : pCurrentItem (0),
       autoSelectDelay(0),
       dragOverItem(0),
       dragDelay (KGlobalSettings::dndEventDelay()),
-      editor (new K3ListViewLineEdit (listview)),
+      editor (0),
       cursorInExecuteArea(false),
       itemsMovable (true),
       selectedBySimpleMove(false),
@@ -109,7 +109,6 @@
       shadeSortColumn(KGlobalSettings::shadeSortColumn())
   {
       renameable.append(0);
-      connect(editor, SIGNAL(done(Q3ListViewItem*,int)), listview, \
SLOT(doneEditing(Q3ListViewItem*,int)));  }
 
   ~K3ListViewPrivate ()
@@ -117,6 +116,12 @@
     delete editor;
   }
 
+  void createEditor (K3ListView *listview)
+  {
+      editor = new K3ListViewLineEdit (listview);
+      connect(editor, SIGNAL(done(Q3ListViewItem*,int)), listview, \
SLOT(doneEditing(Q3ListViewItem*,int))); +  }
+
   Q3ListViewItem* pCurrentItem;
 
   QTimer autoSelect;
@@ -413,8 +418,9 @@
 
 K3ListView::K3ListView( QWidget *parent )
   : Q3ListView( parent ),
-        d (new K3ListViewPrivate (this))
+        d (new K3ListViewPrivate)
 {
+  d->createEditor(this);
   setDragAutoScroll(true);
 
   connect( this, SIGNAL( onViewport() ),



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic