Discussion:
wxNSView +initialize doesn't work with multiple plugins
(too old to reply)
dp51
2009-05-24 02:32:27 UTC
Permalink
Hi,

I'm using intel Mac OS 10.4.11, Xcode 2.5, and wxWidgets 2.9.0 RC3 compiled
with
--enable-debug --with-osx_cocoa --disable-shared.

I made 2 plugins that are statically linked to wxWidgets. Whenever I load
them one
after the other, the 2nd one will just show a blank window with no controls.
I think
the controls are there, but the window is not receiving any events (no
key/mouse
events are received). I think the problem is related to this discussion:

http://www.nabble.com/Obj-C-%22class-unifiying%22--tp10823109p10826917.html

I debugged one of my plugins and I noticed that the wxNSView initialize
method is never
called if it's the 2nd wxWidgets plugin to be loaded. I bypassed initialize
and called
wxOSXCocoaClassAddWXMethods() in wxWidgetImpl::CreateContentView() and now
the problem is gone. But, I'm afraid that somewhere down the line I'll run
into a similar
problem with some other static class method.

Is there an easier fix or a compiler flag to disable this Objective-C
behavior?

Please understand that I'm VERY new to Objective-C. Thanks,

Davis
--
View this message in context: http://www.nabble.com/wxNSView-%2Binitialize-doesn%27t-work-with-multiple-plugins-tp23690111p23690111.html
Sent from the wxWidgets - Users mailing list archive at Nabble.com.
Vadim Zeitlin
2009-05-24 09:24:22 UTC
Permalink
On Sat, 23 May 2009 19:32:27 -0700 (PDT) dp51 <***@yahoo.com> wrote:

d> I made 2 plugins that are statically linked to wxWidgets.

It's a bad idea to use multiple copies of wx in the same application,
while it should work in principle things are much simpler if you link wx
dynamically and so reuse the same instance of the library in all your
plugins.

Beyond this I don't really know if your fix is correct because I don't
understand why is the initialization method not called in the first place.
Could you please explain it if you do?

Thanks,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
dp51
2009-05-24 17:55:00 UTC
Permalink
I may just dynamically link to wxWidgets (maybe with a framework). Thanks
for the suggestion.

It's my understanding that the +(void) initialize method (inherited from
NSObject) is a class method that is called once for every class once the
class is used (e.g. with alloc). The problem is that Objective-C keeps
track of classes by name, so even if you have 2 plugins statically linked to
wxWidgets, Objective-C will only operate on the class object which was
loaded first. (Someone please correct me if I'm wrong).

Thanks,

Davis
Post by Vadim Zeitlin
It's a bad idea to use multiple copies of wx in the same application,
while it should work in principle things are much simpler if you link wx
dynamically and so reuse the same instance of the library in all your
plugins.
Beyond this I don't really know if your fix is correct because I don't
understand why is the initialization method not called in the first place.
Could you please explain it if you do?
--
View this message in context: http://www.nabble.com/wxNSView-%2Binitialize-doesn%27t-work-with-multiple-plugins-tp23690111p23696260.html
Sent from the wxWidgets - Users mailing list archive at Nabble.com.
Loading...