In this line:

NSRect frameRect = [[statusItem view] frame];

the method -view is returning nil, and thus so is -frame, which means
frameRect contains garbage (or NSZeroRect if you're lucky).

Create a dummy view and give it to the status item before asking for the
frame. Keep in mind, you will only get a value relative to the view's
superview, so that'll be useless too.

-Steven

On Wed, Mar 3, 2010 at 2:23 PM, fabian <cocoadevl...@gmail.com> wrote:

> Hi,
>
> 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...
>
> Thanks.
> _______________________________________________
>
> 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/steven.degutis%40gmail.com
>
> This email sent to steven.degu...@gmail.com
>



-- 
Steven Degutis
http://www.thoughtfultree.com/
http://www.degutis.org/
_______________________________________________

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