Re: Cleaning up a window with blocks

2011-09-29 Thread Eric Gorr
Ya, thanks. 

I spotted that almost immediately after I posted the message.

On Sep 29, 2011, at 4:22 PM, Ken Thomases wrote:

> On Sep 29, 2011, at 11:42 AM, Thomas Davie wrote:
> 
>> 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:...
> 
> You can fix that by declaring theObserver with the __block qualifier.
> 
> Cheers,
> 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


Re: Cleaning up a window with blocks

2011-09-29 Thread Ken Thomases
On Sep 29, 2011, at 11:42 AM, Thomas Davie wrote:

> 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:...

You can fix that by declaring theObserver with the __block qualifier.

Cheers,
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


Re: Cleaning up a window with blocks

2011-09-29 Thread Thomas Davie
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 (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/tom.davie%40gmail.com
> 
> This email sent to tom.da...@gmail.com

___

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


Cleaning up a window with blocks

2011-09-29 Thread Eric Gorr
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 (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