From kde-commits Mon Jan 31 23:17:33 2005 From: Joseph Wenninger Date: Mon, 31 Jan 2005 23:17:33 +0000 To: kde-commits Subject: kdelibs/kate/part Message-Id: <20050131231733.69BE71D1DF () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=110721346203348 CVS commit by jowenn: an attempt to fix #96327 M +15 -2 katefactory.cpp 1.71 --- kdelibs/kate/part/katefactory.cpp #1.70:1.71 @@ -34,4 +34,5 @@ #include #include +#include /** @@ -145,4 +146,16 @@ KateFactory::KateFactory () KateFactory::~KateFactory() { + /* ?hack? If MainApplication-Interface::quit is called by dcop the factory gets destroyed before all documents are destroyed eg in kwrite. + This could happen in other apps too. Since the documents try to unregister a new factory is created (in the ::self call) and registered with a + KStaticDeleter which causes a crash. That's why I ensure here that all documents are destroyed before the factory goes down (JOWENN)*/ + while (KateDocument *doc=m_documents.first()) { + s_self=this; /* this is needed because the KStaticDeleter sets the global reference to 0, before it deletes the object it handles. + To prevent a crash again restore the factory pointer temporarily. (jowenn)*/ + delete doc; + s_self=0; + } + /*another solution would be to set a flag in the documents, and inhibit calling of the deregistering methods, but I don't see a problem + if all created objects are deleted before their factory. If somebody sees a problem, let me know*/ + delete m_documentConfig; delete m_viewConfig; @@ -164,7 +177,7 @@ static KStaticDeleter sdFac KateFactory *KateFactory::self () { - if (!s_self) + if (!s_self) { sdFactory.setObject(s_self, new KateFactory ()); - + } return s_self; }