KLibLoader + KPartFactory + loading oneself problem.

Luis Pedro Coelho luis_pedro at netcabo.pt
Sat Jun 7 16:55:02 BST 2003

Hash: SHA1


{see http://bugs.kde.org/show_bug.cgi?id=58904 }

I have been looking into bug 58904.

I have one solution below (not yet commited). I still don't know if it is a 
good one or whether this should be fixed elsewhere (kdecore), so I am posting 
to ask for opinions.

It comes down to the following:

kghostview, the app, is a simple shell dynamically linked to the part. At run 
time, when a print preview window gets called, the same part is loaded (since 
the print preview wants to display postscript as well) and the corresponding 
factory object is constructed. When the preview is finished, the lib is 
unloaded and the factory destroyed.

The problem is that destroying the factory, destroys  KGVFactory::s_instance 
which is still in use by the main application! This leads to crashes later.

Here is my simple fix (attached is full patch against HEAD - works with BRANCH 
even though it doesn't apply directly): In the shell, instead of constructing 
the object directly, do:

- -    m_gvpart = new KGVPart( this, "kgvpart", this, "kgvpart" );
+    m_gvpart = dynamic_cast<KGVPart*>( KLibLoader::self()->factory( 
"libkghostviewpart" )->create( this, "kgvpart", "KGVPart" ) );

This increments the reference count and prevents the library from being 
unloaded and everything seems to work.

Is this a good solution or a hack?
Is there anything else I should be doing? 
Can one consider this a KLibLoader + Factory bug? Or is it a plain old 
kghostview bug?

- -- 
Luis Pedro Coelho

The carrot tax, see:

Version: GnuPG v1.0.7 (GNU/Linux)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmail-attach.3mwDZe
Type: text/x-diff
Size: 942 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030607/52166b46/attachment.diff>

More information about the kde-core-devel mailing list