Re: Cleaning up a window with blocks
Re: Cleaning up a window with blocks
- Subject: Re: Cleaning up a window with blocks
- From: Thomas Davie <email@hidden>
- Date: Thu, 29 Sep 2011 17:42:11 +0100
A quick scan over the code says that your issue is that you're referring to theObserver inside theObserver, which, when the block is constructed, as not yet been assigned the result of addObserverForName:...
Bob
if (*ra4 != 0xffc78948) { return false; }
On 29 Sep 2011, at 17:37, Eric Gorr wrote:
> The intent of the following code is to implement a quick and easy way to bring up a window and provide a way to clean up after it closes. The problem is that it is crashing. I believe I am missing something obvious here and was hoping that someone could remove the blinders...
>
>
> - (void) displayWindow
> {
> NSURL* documentURL;
> NSWindowController* controller;
> id theObserver;
>
> documentURL = [[NSBundle mainBundle] URLForResource:@"document" withExtension:@"rtf"];
> controller = [[NSWindowController alloc] initWithWindowNibName:@"DocDisplay"];
>
> theObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowWillCloseNotification
> object:[controller window]
> queue:nil
> usingBlock:^(NSNotification *note)
> {
> [[NSNotificationCenter defaultCenter] removeObserver:theObserver];
>
> [[controller window] orderOut:self];
> [controller autorelease];
> }];
>
> NSArray* subviews = [[[controller window] contentView] subviews];
> NSScrollView* scrollView = [subviews objectAtIndex:0];
> NSTextView* rtfView = [scrollView documentView];
>
> [rtfView readRTFDFromFile:[documentURL path]];
>
> [[controller window] setTitle:@"TheTitle"];
>
> [[controller window] makeKeyAndOrderFront:self];
> }
>
>
> Here's the relevant part of the crash log:
>
>
> 0 libobjc.A.dylib objc_msgSend_vtable13 + 13
> 1 libobjc.A.dylib objc_retain + 19
> 2 libsystem_blocks.dylib _Block_object_assign + 336
> 3 com.company.app __copy_helper_block_ + 67
> 4 libsystem_blocks.dylib _Block_copy_internal + 203
> 5 com.apple.CoreFoundation -[NSBlock copy] + 39
> 6 com.apple.Foundation +[__NSObserver observerWithCenter:queue:name:object:block:] + 211
> 7 com.apple.Foundation -[NSNotificationCenter addObserverForName:object:queue:usingBlock:] + 134
> 8 com.company.app -[TMBrowserAppDelegate displayWindow:] + 494
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden