Thanks for your replies. I understand that the -frame message is returning
garbage. What I don't understand is why statusBar, statusItem or the
statusItem's view is nil during (but not after) the unarchiving of the nib,
or (on 10.5.8) even shortly after NSApp is fully loaded. Or is it? If I
can't know for sure that NSApp really did finish launching when this
delegate method is called, what's the point of having it at all? What I'd
like is a -applicationReallyTrulyDidFinishLaunchingNoKidding notification,
so I can instantiate the status bar item without having to worry about it
mysteriously being nil at the time.

So, I don't know. Should I put a timer in -applicationDidFinishLaunching and
create the status bar item after a short delay? If so, how long? Is 1 second
enough? Two seconds? It seems all I can do is guess, as there is no
mentioning of any of this in the docs.

Or should I go with Steven's advice, and feed the status item with a dummy
view first? What difference would it make?


On Wed, Mar 3, 2010 at 9:14 PM, Ken Thomases <k...@codeweavers.com> wrote:

> On Mar 3, 2010, at 1:23 PM, fabian wrote:
>
> > I once noticed that this code caused an assertion failure when placed
> > in awakeFromNib.
> >
> > NSStatusBar *statusBar = [NSStatusBar systemStatusBar];
> > statusItem = [[statusBar statusItemWithLength:26] retain];
> > NSRect frameRect = [[statusItem view] frame];
> > MyStatusItemView *theView = [[MyStatusItemView alloc]
> > initWithFrame:frameRect];
> > [theView setDelegate:self];
> > [statusItem setView:theView];
> > [theView release];
> >
> > I didn't think much about it then - I simply moved the code to
> > applicationDidFinishLaunching and everything was fine. But now I'm
> > told the app is crashing nevertheless, AFAIK under 10.5.8 only:
> >
> > 3/2/10 3:12:49 PM MyProcess[13261] *** Assertion failure in
> > -[MyStatusItemView initWithFrame:],
> > /SourceCache/AppKit/AppKit-
> > 949.54/AppKit.subproj/NSView.m:1099
> > 3/2/10 3:12:49 PM MyProcess[13261] Uninitialized rectangle passed to
> > [View initWithFrame:].
> > 3/2/10 3:13:38 PM com.apple.launchd[115]
> > ([0x0-0x104104].my.process[13261]) Exited abnormally: Interrupt
> >
> > It's definitely related to the app/nib not being up and ready to go.
> > I'm displaying a dialog on first run in awakeFromNib. When the dialog
> > is displayed (delaying the execution of this code), it works fine. On
> > second launch it's a no go.
> >
> > How can the system status bar not be initialized at this point? It's
> > not even part of the nib...
>
> Probably, the -frame message is being sent to nil.  That could happen if
> statusBar, statusItem, or the statusItem's view is unavailable at the point
> where you're trying to access it.
>
> For some messages, messaging nil gives you a well-defined result (0).  But
> for messages which return a struct, you get ill-defined results (garbage).
>
> http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjectiveC/Articles/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-SW7
>
> Regards,
> Ken
>
>
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to