Professional Web Applications Themes

Can only access user-defined class after use by other plugin target - Mac Programming

I have a project I'm developing in Project Builder that has several targets (a main application bundle plus a bunch of plugins). In one of the targets I make use of an NSObject subclass that does some math stuff ( it is a Matrix class). As far as I can recall, the only things I needed to do to make this Matrix class available for my target was to add the # import "MyClass.h" statement and to make sure the sources for my Matrix class were included in the 'sources' field in the targets pane. Both of the targets that ...

  1. #1

    Default Can only access user-defined class after use by other plugin target


    I have a project I'm developing in Project Builder that has several
    targets (a main application bundle plus a bunch of plugins). In one of
    the targets I make use of an NSObject subclass that does some math stuff (
    it is a Matrix class). As far as I can recall, the only things I needed
    to do to make this Matrix class available for my target was to add the #
    import "MyClass.h" statement and to make sure the sources for my Matrix
    class were included in the 'sources' field in the targets pane. Both of
    the targets that use the Matrix class are plugin bundles used by the
    main target.

    I recently added another target, and added the #import and source
    dependencies. Even though the new target compiles fine with instances
    of the Matrix class declared and used, when I hit the first line of code
    in which a message is sent to one of these objects the program bombs
    with 'Program exited with status 1'. I can declare the object, just not
    use it.

    The really strange thing is that if I run the plugin based on the
    original target to use the Matrix class (which has continued to work
    throughout), the newer target will subsequently work (until I restart
    the application). It's as if the class has somehow been loaded by the
    invocation of the first target/plugin in a way that is not happening
    with my more recently written target.

    I've been racking my brain trying to spot differences in the build
    settings for the two targets, but have found nothing.

    This is probably some dumb typo or obvious omission somewhere, but I'm
    just not seeing it. If somebody has an idea of what might account for
    this kind of behaviour, I'd be very happy to hear it!

    ER
    Eric Guest

  2. #2

    Default Re: Can only access user-defined class after use by other plugintarget

     

    Uh - I suppose it would help to mention it's a Cocoa application written
    in Objective-C

    Get the problem using both gcc-3.1 and 3.2

    ER
    Eric Guest

  3. #3

    Default Re: Can only access user-defined class after use by other plugintarget

    >> I have a project I'm developing in Project Builder that has several 
    >
    > Uh - I suppose it would help to mention it's a Cocoa application
    > written in Objective-C
    >
    > Get the problem using both gcc-3.1 and 3.2[/ref]

    Made some progress on this - has been very educational...

    Have been running the application through Project Builder, and
    monitoring the PB console for logging messages. Frustratingly, there
    were none! Finally I checked the system console, which turned out to be
    a good thing. Seems like there are some messages from the Objective-C
    runtime (or somewhere) that go to the system console even when the app
    is run from PB. Anyway, here are some messages that give a clue to the
    problem (paths have been edited for clarity):

    Oct 16 13:03:35 heme MyApplication: objc: Both /MyApplication.app/
    Contents/PlugIns/Filter1.plugin/Contents/MacOS/Filter1 and /
    MyApplication.app/Contents/PlugIns/Filter2.plugin/Contents/MacOS/Filter2
    have implementations of class MyFilter.
    ...
    Oct 16 13:03:48 heme MyApplication: objc: thread is already initializing
    this class!

    Note that the first message is something non-fatal that had always been
    generated (never noticed it before). Still it is a clue to the problem,
    as is the second (fatal) message.

    Sounds like the way I am implementing plugins using a class instead of a
    protocol is wrong - there is a thread on this in the CocoaDev archives:

    http://cocoa.mamasam.com/COCOADEV/2003/09/1/72104.php

    The above thread contains some interesting comments on the merits of
    various plugin schemes (class vs. protocol...)

    ER



    Eric Guest

  4. #4

    Default Re: Can only access user-defined class after use by other plugin target

    In article <mgh.harvard.edu>,
    Eric Raas <net> wrote:
     
    > >
    > > Uh - I suppose it would help to mention it's a Cocoa application
    > > written in Objective-C
    > >
    > > Get the problem using both gcc-3.1 and 3.2[/ref]
    >
    > Made some progress on this - has been very educational...
    >
    > Have been running the application through Project Builder, and
    > monitoring the PB console for logging messages. Frustratingly, there
    > were none! Finally I checked the system console, which turned out to be
    > a good thing. Seems like there are some messages from the Objective-C
    > runtime (or somewhere) that go to the system console even when the app
    > is run from PB. Anyway, here are some messages that give a clue to the
    > problem (paths have been edited for clarity):
    >
    > Oct 16 13:03:35 heme MyApplication: objc: Both /MyApplication.app/
    > Contents/PlugIns/Filter1.plugin/Contents/MacOS/Filter1 and /
    > MyApplication.app/Contents/PlugIns/Filter2.plugin/Contents/MacOS/Filter2
    > have implementations of class MyFilter.
    > ..
    > Oct 16 13:03:48 heme MyApplication: objc: thread is already initializing
    > this class![/ref]
    [snip]

    Simply put, you have two classes with the same name defined in two
    different plugins, which is not good.

    It sounds to me like the MyFilter classes are the classes that implement
    your filter. Is this correct? Each plugin then has a different MyFilter
    class that implements that particular filter.

    You have to change the names. Two plugins can't define classes with the
    same name, basically. This is somewhat of a shortcoming of Objective-C,
    and it's why you need to use prefixes on everything.

    Mac OS X also does not support unloading of plugins, so you can't use
    one plugin, unload it, then use the other one. You have to quit and
    restart the app to really unload it, which you probably don't want to do.

    I haven't actually implemented a plugin system myself, but I have
    written a preference pane, and issues like this are covered in the
    preference pane doentation.
    Michael Guest

  5. #5

    Default Re: Can only access user-defined class after use by other plugintarget

    ... 

    This is sort of correct - each plugin is a subclass of MyFilter but
    apparently to implement these subclasses it's necessary to reimplement
    the MyFilter class each time, which leads to the warnings.
     

    In the CocoaDev thread (see my previous post in this thread) it was
    indicated that an acceptable alternative would be to turn the filter
    superclass into a framework that other filters could link against. In
    fact I was able to get rid of my fatal Matrix class error using this
    approach (made a framework based on the class). I will also modify the
    filter organization to use a framework for now - I'm surprised I never
    had any problems before as I've used this scheme for a while now (have
    not actually released the application though). Another approach to
    plugins that seems popular is the use of protocols - it seems like this
    might be more flexible, although it's not clear if there are any
    downsides.

    On another note, does this mean that if any two Objective-C programs use
    the same name for a class and are run at the same time that a problem
    will arise? Or is it just an issue because my two plugins got loaded by
    the same Objective-C program?
     

    Thanks - I will have to check that out. Somehow this caught me by
    surprise, but in the end I think it will be very educational.

    ER
    Eric Guest

  6. #6

    Default Re: Can only access user-defined class after use by other plugin target

    In article <verizon.net>,
    Eric Raas <net> wrote:
     

    No, we have protected memory, and so separate ObjC runtimes, separate
    everything. It's only a problem when loading classes into the same
    application. So you don't need to worry about prefixing or anything like
    that when you write a normal app, but you do need to worry about it when
    you write a plugin, or a preference pane, anything like that.
    Michael Guest

Similar Threads

  1. Replies: 2
    Last Post: October 5th, 07:20 PM
  2. Multiple class modules defined within a single vb activex dll
    By mike watkins in forum ASP Components
    Replies: 0
    Last Post: October 10th, 10:38 AM
  3. calling a user defined java class method .....
    By Toby z in forum PHP Development
    Replies: 0
    Last Post: August 20th, 06:39 AM
  4. User-defined class coercion?
    By Yukihiro Matsumoto in forum Ruby
    Replies: 4
    Last Post: August 6th, 01:23 PM
  5. Replies: 0
    Last Post: August 6th, 03:54 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139