Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Multi-window document app

Multi-window document app
Thread Tools
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jan 9, 2003, 01:29 AM
 
Hello,

I seem to be having some trouble with a document based app. I have multiple windowcontrollers being created from the documents makeDocumentControllers method. Each window type is loaded from different NIB files. The problem comes if the user closes one of the windows and its windowController. If I click on the menu or make a selection from the dockmenu or try to create another documentcontroller the app crashes with Sigbus.

Some help or a point in the right direction would be much appriciated.

type r
I be that insane n***a from the psycho ward.
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jan 9, 2003, 01:00 PM
 
anyone?
I be that insane n***a from the psycho ward.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jan 9, 2003, 05:45 PM
 
Well, it sounds like one of the window controllers is being released when it shouldn't be. I don't know what more I can say since I have no idea what your code looks like, and thus no idea what mistakes it contains. If you feel like posting a small example that duplicates the problem, it would be a lot more helpful in pinpointing it.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jan 9, 2003, 10:36 PM
 
Thanks, here is the code

Code:
-(void) makeWindowControllers { tableController = [[TableDataController alloc] initWithWindowNibName:@"TableData" ]; if(![windowControllers containsObject: tableController]) { [tableController setDocument: self]; [tableController windowWillLoad]; [windowControllers addObject: tableController]; } } -(void) removeWindowController:(NSWindowController*) windowController { if([windowControllers containsObject: windowController]) { [windowController autorelease]; } }
Thank you for your help

type R
I be that insane n***a from the psycho ward.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jan 10, 2003, 06:05 AM
 
I think your problem is caused by the -removeWindowController: method. It looks like you're releasing an object in an array without removing it from the array. Then, when you try to access the objects in the array, that one has been deallocated and your program blows up.

You really don't need to implement that method, or have the windowControllers array. Just implement your -makeWindowControllers like so:
Code:
- (void)makeWindowControllers { tableController = [[TableDataController alloc] initWithWindowNibName:@"TableData"]; //Adds the controller to your document's array and makes this its document. [self addWindowController:tableController]; //Since the array retains the controller for your document, no need to keep a hold of it. [tableController release]; }
And if you need to access the array of window controllers, just use NSDocument's -windowControllers method.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
asd
Fresh-Faced Recruit
Join Date: Sep 2001
Status: Offline
Reply With Quote
Jan 10, 2003, 09:57 AM
 
There are a few changes you should make:
First of all in the -makeWindowControllers method you need to call [self addWindowContoller:tableController] to add the newly created window controller to the documents list of window controllers. That method automstically sets the tabelController's document correctly so can eliminate that part of the code.

i.e. your code should just be:

-(void) makeWindowControllers
{
tableController = [[TableDataController alloc]initWithWindowNibName:@"TableData" ];

[self addWindowController:tableController];

}

Secondly, i agree that you don't need to overide -removeWindowController method (AFAIK).

Hope that helps
     
Junior Member
Join Date: Oct 2001
Status: Offline
Reply With Quote
Jan 11, 2003, 12:13 AM
 
i am an idiot. Simple overthinking.

Thanks
I be that insane n***a from the psycho ward.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2