Version: unknown (using KDE 3.1.3) Installed from: SuSE Compiler: gcc version 3.2 OS: Linux (i686) release 2.4.20-athlon Hi, KViewerPart cause a crash in the app that loads the kviewerpart library if the requested viewerpart (e.g. dvi, pdf) is not installed. I have the following code to load the DVI viewer part (using kviewpart) in Kile: KLibFactory *dvifactory; dvifactory = KLibLoader::self()->factory("kviewerpart"); if (!dvifactory) { KMessageBox::error(this, i18n("blabla")); return; } dvipart =(KParts::ReadOnlyPart *)dvifactory->create(topWidgetStack, "kviewerpart", "KViewPart", "dvi"); However if the kviewpart library is present, but the dvi part isn't, kviewpart crashes and drags Kile along with it. The problem is in KViewPart::KViewPart(). If the requested library does not exist, it calls ::exit(-1). Is there any way I can prevent this to happen? I mean there should be a graceful exit and a change for Kile to deal with the problem. best, Jeroen
CVS commit by waba: Don't exit when we can't load part. (BR66131) Please report back if this fixes BR66131 so it can be added to KDE_3_2_BRANCH as well. CCMAIL: 66131@bugs.kde.org M +14 -7 kviewpart.cpp 1.89 M +2 -0 kviewpart.h 1.43 --- kdegraphics/kviewshell/kviewpart.cpp #1.88:1.89 @@ -75,5 +75,10 @@ KParts::Part *KViewPartFactory::createPa if (args.count() >= 1) partname = args[0]; - KParts::Part *obj = new KViewPart(partname, parentWidget, widgetName, parent, name); + KViewPart *obj = new KViewPart(partname, parentWidget, widgetName, parent, name); + if (!obj->isValid()) + { + delete obj; + return 0; + } return obj; } @@ -89,5 +94,5 @@ KInstance *KViewPartFactory::instance() KViewPart::KViewPart(QString partname, QWidget *parentWidget, const char *widgetName, QObject *parent, const char *name) - : KViewPart_Iface(parent, name), _partname(partname), _numberOfPages(0), + : KViewPart_Iface(parent, name), _partname(partname), multiPage(0), _numberOfPages(0), _currentPage(0) { @@ -137,7 +142,9 @@ KViewPart::KViewPart(QString partname, Q multiPage = (KMultiPage*) factory->create(mainWidget, QString("k%1").arg(_partname).utf8(), "KPart"); } else { - KMessageBox::error(mainWidget, i18n("No module (%1) found").arg(_partname)); - ::exit(-1); + KMessageBox::error(parentWidget, i18n("No module (%1) found").arg(_partname)); } + if (!multiPage) + return; // Abort + hbox->addWidget(multiPage->widget()); @@ -272,7 +279,7 @@ KViewPart::KViewPart(QString partname, Q KViewPart::~KViewPart() { + if (multiPage) writeSettings(); delete multiPage; - if ( tmpUnzipped != 0L ) delete tmpUnzipped; } --- kdegraphics/kviewshell/kviewpart.h #1.42:1.43 @@ -53,4 +53,6 @@ public: virtual ~KViewPart(); + bool isValid() { return multiPage; } + // Returns a description of the current page size, for use in the // statusbar of the kviewshell that embeds this KViewPart.
Thanks for the patch! It indeed fixes this bug. I've tested it against the KDE_3_2_BRANCH, so it is safe to apply it there as well. AFAIC you can close this bug. best, Jeroen
Why isn't the patch backported yet? I could do it for you if you want, just give me a go-ahead. best, Jeroen
Yes, please, feel free to backport the patch. Bye, Matthias.
Done. best, Jeroen
The bug is back again, can you please fix it before KDE 3.4.1 is out? best, Jeroen
Oops, reopened wrong bug, terribly sorry about that!