 |
 |
Multi-window document app
|
 |
|
 |
|
Junior Member
Join Date: Oct 2001
Status:
Offline
|
|
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
|
|
|
|
|
I be that insane n***a from the psycho ward.
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
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
|
|
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
|
|
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'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2001
Status:
Offline
|
|
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
|
|
i am an idiot. Simple overthinking.
Thanks
|
|
I be that insane n***a from the psycho ward.
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|