Re: Standard Cocoa Save Panel crashing in Leopard
Re: Standard Cocoa Save Panel crashing in Leopard
- Subject: Re: Standard Cocoa Save Panel crashing in Leopard
- From: John Nairn <email@hidden>
- Date: Wed, 26 Dec 2007 11:32:16 -0800
Thanks Fritz. I was a little fuzzy on why I even wrote the text
container code as I did, but then remembered it came directly from
this Apple documention:
"To use NSLayoutManager to draw a text string directly into a view,
you must create and initialize the three basic nonview components of
the text system. First create an NSTextStorage object to hold the
string. Then create an NSTextContainer object to describe the
geometric area for the text. Then create the NSLayoutManager object
and hook the three objects together by adding the layout manager to
the text storage object and adding the text container to the layout
manager. The code in Listing 1, which could reside in the view’s
initWithFrame: method, illustrates this procedure.
NSTextStorage *textStorage = [[NSTextStorage alloc]
initWithString:@"This is the text string."];
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
NSTextContainer *textContainer = [[NSTextContainer alloc] init];
[layoutManager addTextContainer:textContainer];
[textContainer release];
[textStorage addLayoutManager:layoutManager];
[layoutManager release];
You can release the text container because the layout manager retains
it, and you can release the layout manager because the text storage
object retains it."
An this NSView works fine and displays the text as expected, I think
the initialization is OK. I still suspect it, however, in the save
panel crashes because they occur when the layout manager sends a
message to a deallocated NSTextStorage object and this is the only
text storage object in my application? My object retains it an
releases it. I have not subclassed it so I assume the Cocoa
implementation properly removes itself from notifications when it is
deallocated.
On Dec 21, 2007, at 7:00 PM, Fritz Anderson wrote:
On 21 Dec 2007, at 4:21 PM, John Nairn wrote:
textContainer = [[NSTextContainer alloc] init];
Perhaps it is not the source of your problem, but I wonder if -init
is a proper initializer for NSTextContainer. The designated
initializer is initWithContainerSize:.
— F
I posted messages recently about frequent crashes in standard open
and save panels (in Leopard only) and was assured it must be bug in
my code. The crash log looked like it crashed on a message
involving NSTextStorage and indeed I found an NSTextStorage object
I was using to format labels for a graphic view. I was releasing
that object's layout manager, but not the object. That sounded like
the problem. I fixed it and the crashing stopped for a couple of
days. Today it crashed again during a simple save as panel and the
crash log (see below) still mentions NSTextStorage. I looked again,
but can not find any more NSTextStorage objects in my code.
I have run with NSZombies enabled, but the crashes are rare and
thus hard to catch. Prior to the fix of my NSTextStorage object bug
I got
2007-12-04 16:56:44.131 NairnFEAMPM[27778:10b] *** -
[NSLayoutManager
textStorage:edited:range:changeInLength:invalidatedRange:]: message
sent to deallocated instance 0x167c9420
---------------
John Nairn (1-541-737-4265, FAX:1-541-737-3385)
Professor and Richardson Chair
Web Page: http://woodscience.oregonstate.edu/faculty/Nairn
FEA/MPM Web Page: http://oregonstate.edu/~nairnj
_______________________________________________
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