I'm trying to write a dylib extension to the Tcl/Tk scripting language that updates an application icon with a call to [NSApp setApplicationIconImage]. My code works as expected until it is time for me to restore the original application icon. At that point my app quits with this error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Creating more than one Application'

I have multiple calls to NSApp, which is apparently the problem--I am not correctly setting the NSApp global. I've been advised to call NSApplicationLoad(), since Tcl/Tk is currently based on Carbon, but I'm not sure where to do this.

The relevant code is below. Any advice is appreciated. --Kevin

--
#import "cocoadock.h"

@implementation CocoaDock

// cocoa command to set the dock icon.

-(int) switchIcon: (NSString *) iconPath  {
        
        
        //set up autorelease pool
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        
      //convert file path to URL
     iconURL = [[NSURL alloc] initFileURLWithPath: iconPath];

    //create image from URL
     newIcon = [[NSImage alloc] initWithContentsOfURL: iconURL];

        //set the new icon
     [NSApp setApplicationIconImage: newIcon];

    //release the memory
     [newIcon release];
         [iconURL release];
        
         [pool release];                

        return 0;
}


-(int) origIcon {
                
        //set up autorelease pool
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

        //restore the app icon
    [NSApp setApplicationIconImage:nil];

     [pool release];

     return 0;

}


@end

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to