Cocoa Newbie Crash Question

  • I have a very simple Cocoa/IB app that crashes and dies on startup.
    All I want to do is start the app and put up one single alert. Here
    is my main.m file:

    #import <Cocoa/Cocoa.h>
    #include <Foundation/Foundation.h>

    int main( int argc, const char *argv[] )
    {
        NSAutoreleasePool    *pool = NULL;

        pool = [[NSAutoreleasePool alloc] init];

        NSRunCriticalAlertPanel( @"This is an example of NSCriticalAlertPanel",
                                  @"Alerts are surprisingly easy in Cocoa.",
                                  @"",
                                  @"",
                                  @"OK",
                                  nil,
                                  nil    );

        [ pool release ];

        return NSApplicationMain( argc, argv );
    }

    This is a basic Cocoa app created using Project Builder's "Cocoa
    Application" template running under 10.2. No other modifications have
    been made to the project.

    What am I doing wrong?

    Here is the crash log from Console:

    **********

    Date/Time:  2003-10-26 18:17:18 -0800
    OS Version: 10.2.7 (Build 6S80)
    Host:      G4

    Command:    StorageTest
    PID:        981

    Exception:  EXC_BREAKPOINT (0x0006)
    Code[0]:    0x00000001Code[1]:    0x97e5497c

    Thread 0 Crashed:
      #0  0x97e5497c in _NSRaiseError
      #1  0x97e70204 in -[NSAssertionHandler
    handleFailureInMethod:object:file:lineNumber:description:]
      #2  0x9309ed1c in -[NSView lockFocus]
      #3  0x930c1bf0 in _NXAllocateImageCache
      #4  0x93115210 in -[NSCachedImageRep
    _initWithSize:depth:separate:alpha:allowDeep:]
      #5  0x930ccee8 in -[NSImage lockFocus]
      #6  0x930f43e8 in -[NSImage _expandRep:]
      #7  0x93091f40 in -[NSImage _expand]
      #8  0x930e0958 in -[NSImage copyWithZone:]
      #9  0x9317adf0 in -[NSAlert
    buildAlertStyle:title:message:first:second:third:args:]
      #10  0x933bd288 in _NXDoLocalRunAlertPanel
      #11  0x933730bc in NSRunCriticalAlertPanel
      #12  0x00003cd0 in main (main.m:20)
      #13  0x000039ec in _start (crt.c:267)
      #14  0x0000386c in start

    PPC Thread State:
      srr0: 0x97e5497c srr1: 0x0002f030                vrsave: 0x00000000
        xer: 0x00000000  lr: 0x97e54958  ctr: 0x97df3e2c  mq: 0x00000000
        r0: 0x00000000  r1: 0xbffff230  r2: 0x28000447  r3: 0xa7e02644
        r4: 0x9068d51c  r5: 0x20000000  r6: 0xbfffef10  r7: 0x00000000
        r8: 0x00048010  r9: 0xa7df0294  r10: 0x00000001  r11: 0x00000000
        r12: 0x28000447  r13: 0x00000000  r14: 0x00000000  r15: 0x00000000
        r16: 0xa309ab84  r17: 0x000858f0  r18: 0x00005000  r19: 0x00000000
        r20: 0x00048010  r21: 0x00000001  r22: 0x00000000  r23: 0x00105418
        r24: 0xbffff480  r25: 0x00000080  r26: 0x0012d640  r27: 0xa3086110
        r28: 0x0012d570  r29: 0x0012d700  r30: 0x00000000  r31: 0x97e5489c

    Thanks,

    James
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On Sunday, October 26, 2003, at 06:34  PM, James Masasaki wrote:

    > int main( int argc, const char *argv[] )
    > {
    > NSAutoreleasePool    *pool = NULL;
    >
    > pool = [[NSAutoreleasePool alloc] init];
    >
    > NSRunCriticalAlertPanel( @"This is an example of
    > NSCriticalAlertPanel",
    [...]
    > What am I doing wrong?

    You called NSRunCriticalAlertPanel(), an AppKit function, before you
    called either NSApplicationMain() or NSApplicationLoad(). You must call
    one of those functions before you can do just about anything with the
    AppKit, or you're going to have problems.

    I have not tested this on your example, but you may have better luck by
    calling NSApplicationLoad() before NSRunCriticalAlertPanel()...

    Also, you could consolidate those first two lines of main() and remove
    a few redundant CPU instructions, like this:
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    Nick Zitzmann
    AIM/iChat: dragonsdontsleep
    Check out my software page: http://seiryu.home.comcast.net/

    "I have always wished that my computer would be as easy to use as my
    telephone. My wish has come true. I no longer know how to use my
    telephone." - Bjarne Stroustrup
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • In general, there is no need to rewrite the main.m file.

    Create some IB GUI and call you code through callbacks.

    Am Montag, 27.10.03 um 03:34 Uhr schrieb James Masasaki:

    > I have a very simple Cocoa/IB app that crashes and dies on startup.
    > All I want to do is start the app and put up one single alert. Here
    > is my main.m file:
    >
    > #import <Cocoa/Cocoa.h>
    > #include <Foundation/Foundation.h>
    >
    > int main( int argc, const char *argv[] )
    > {
    > NSAutoreleasePool    *pool = NULL;
    >
    > pool = [[NSAutoreleasePool alloc] init];
    >
    > NSRunCriticalAlertPanel( @"This is an example of
    > NSCriticalAlertPanel",
    > @"Alerts are surprisingly easy in
    > Cocoa.",
    > @"",
    > @"",
    > @"OK",
    > nil,
    > nil    );
    >
    >
    >
    > [ pool release ];
    >
    > return NSApplicationMain( argc, argv );
    > }
    >
    > This is a basic Cocoa app created using Project Builder's "Cocoa
    > Application" template running under 10.2. No other modifications have
    > been made to the project.
    >
    > What am I doing wrong?
    >
    > Here is the crash log from Console:
    >
    > **********
    >
    > Date/Time:  2003-10-26 18:17:18 -0800
    > OS Version: 10.2.7 (Build 6S80)
    > Host:      G4
    >
    > Command:    StorageTest
    > PID:        981
    >
    > Exception:  EXC_BREAKPOINT (0x0006)
    > Code[0]:    0x00000001Code[1]:    0x97e5497c
    >
    > Thread 0 Crashed:
    > #0  0x97e5497c in _NSRaiseError
    > #1  0x97e70204 in -[NSAssertionHandler
    > handleFailureInMethod:object:file:lineNumber:description:]
    > #2  0x9309ed1c in -[NSView lockFocus]
    > #3  0x930c1bf0 in _NXAllocateImageCache
    > #4  0x93115210 in -[NSCachedImageRep
    > _initWithSize:depth:separate:alpha:allowDeep:]
    > #5  0x930ccee8 in -[NSImage lockFocus]
    > #6  0x930f43e8 in -[NSImage _expandRep:]
    > #7  0x93091f40 in -[NSImage _expand]
    > #8  0x930e0958 in -[NSImage copyWithZone:]
    > #9  0x9317adf0 in -[NSAlert
    > buildAlertStyle:title:message:first:second:third:args:]
    > #10  0x933bd288 in _NXDoLocalRunAlertPanel
    > #11  0x933730bc in NSRunCriticalAlertPanel
    > #12  0x00003cd0 in main (main.m:20)
    > #13  0x000039ec in _start (crt.c:267)
    > #14  0x0000386c in start
    >
    > PPC Thread State:
    > srr0: 0x97e5497c srr1: 0x0002f030                vrsave: 0x00000000
    > xer: 0x00000000  lr: 0x97e54958  ctr: 0x97df3e2c  mq: 0x00000000
    > r0: 0x00000000  r1: 0xbffff230  r2: 0x28000447  r3: 0xa7e02644
    > r4: 0x9068d51c  r5: 0x20000000  r6: 0xbfffef10  r7: 0x00000000
    > r8: 0x00048010  r9: 0xa7df0294  r10: 0x00000001  r11: 0x00000000
    > r12: 0x28000447  r13: 0x00000000  r14: 0x00000000  r15: 0x00000000
    > r16: 0xa309ab84  r17: 0x000858f0  r18: 0x00005000  r19: 0x00000000
    > r20: 0x00048010  r21: 0x00000001  r22: 0x00000000  r23: 0x00105418
    > r24: 0xbffff480  r25: 0x00000080  r26: 0x0012d640  r27: 0xa3086110
    > r28: 0x0012d570  r29: 0x0012d700  r30: 0x00000000  r31: 0x97e5489c
    >
    > Thanks,
    >
    > James
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Read the documentation on NSApplication.  It describes what basically
    happens in NSApplicationMain.  In particular, your application isn't
    connected to the window server until it calls [NSApplication
    sharedApplication].  I suspect that you won't be able to create a Cocoa
    alert dialog until after that method has been called.

    On 26 Oct, 2003, at 9:39 PM, <cocoa-dev-request...> wrote:

    > I have a very simple Cocoa/IB app that crashes and dies on startup.
    > All I want to do is start the app and put up one single alert. Here
    > is my main.m file:
    >

                                                      Michael Sullivan
                                                      <imikey...>
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month october 2003 next month
MTWTFSS
    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    
Go to today