Re: Appending string to NSTextView crashing app
Re: Appending string to NSTextView crashing app
- Subject: Re: Appending string to NSTextView crashing app
- From: Evan Moseman <email@hidden>
- Date: Wed, 25 Apr 2007 22:42:14 -0400
A button is linked to:
- (IBAction)startAppButton:(id)sender
{
[self appendString:@"Starting notification event capture..."
toView:applicationTextView];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(appNotificationObserver:)
name:nil object:nil];
}
The selector is this function:
- (void)appNotificationObserver:(NSNotification *)note
{
NSLog(@"app note: %@", [note name]);
[self appendString:[note name] toView:applicationTextView];
}
************************************************************************
*****
The NSLog call can run without crashing. The [note name] class is a
NSCFString. I've enabled a bunch of memory tracing environment
variables:
NSZombieEnable
MallocStackLogging
MallocScribble
MallocStackLoggingNoCompact
I am still not getting any useful information from the debugger after
a crash. After looking at the output from malloc_history, I'm not
getting anything yet, there is a huge amount of information to trudge
through, and the last malloc's this app called for are associated
with preferences. And, I haven't implemented anything with preferences:
...
1 calls for 3 bytes: thread_a000cfc0 |0x1 | start | start | main |
NSApplicationMain | +[NSBundle mainBundle] | +[NSUserDefaults
standardUserDefaults] | +[NSLanguageContext _resetAlternateICUValues]
| udat_open | icu::DateFormat::create(icu::DateFormat::EStyle,
icu::DateFormat::EStyle, icu::Locale const&) |
icu::SimpleDateFormat::SimpleDateFormat[in-charge]
(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale
const&, UErrorCode&) | icu::SimpleDateFormat::construct
(icu::DateFormat::EStyle, icu::DateFormat::EStyle, icu::Locale
const&, UErrorCode&) | icu::SimpleDateFormat::initializeCalendar
(icu::TimeZone*, icu::Locale const&, UErrorCode&) |
icu::Calendar::createInstance(icu::TimeZone*, icu::Locale const&,
UErrorCode&) | ures_getFunctionalEquivalent | ures_open |
ures_getPath | u_getIntPropertyMaxValue | u_getIntPropertyMaxValue |
malloc
1 calls for 1 bytes: thread_a000cfc0 |0x1 | start | start | main |
NSApplicationMain | +[NSBundle mainBundle] | +[NSUserDefaults
standardUserDefaults] | -[NSUserDefaults initWithUser:] |
_CFPreferencesStandardDomain | _CFPreferencesCachePrefixForUserHost |
_CFUserName | _CFUpdateUserInfo | getpw | getpw_internal |
lu_getpwnam | extract_user | strdup | malloc
1 calls for 1 bytes: thread_a000cfc0 |0x1 | start | start | main |
NSApplicationMain | +[NSBundle mainBundle] | +[NSUserDefaults
standardUserDefaults] | -[NSUserDefaults initWithUser:] |
_CFPreferencesStandardDomain | _CFPreferencesCachePrefixForUserHost |
_CFUserName | _CFUpdateUserInfo | getpw | getpw_internal | copy_user
| strdup | malloc
1 calls for 1 bytes: thread_a000cfc0 |0x1 | start | start | main |
NSApplicationMain | +[NSBundle mainBundle] | +[NSUserDefaults
standardUserDefaults] | -[NSUserDefaults initWithUser:] |
_CFPreferencesStandardDomain | _CFPreferencesCachePrefixForUserHost |
_CFUserName | _CFUpdateUserInfo | getpw | getpw_internal |
lu_getpwnam | extract_user | strdup | malloc
So, all of the code in this e-mail makes up 90% of the app. This is
a very small amount of code, for the trouble. :)
Thanks for all of your help!
--
Evan
On Apr 24, 2007, at 11:52 PM, PGM wrote:
On 24-Apr-07, at 23:24 PM, Evan Moseman wrote:
Thanks for the reply, I made the changes you suggested:
- (void)appendString:(NSString *)string toView:(NSTextView *)view
{
if (string == nil) { return; }
string = [string stringByAppendingString:@"\n"];
NSAttributedString *stringToAppend =
[[NSAttributedString alloc] initWithString:string];
[[view textStorage] appendAttributedString:stringToAppend];
[stringToAppend release];
}
Even shorter (typed in Mail):
- (void)appendString:(NSString *)string toView:(NSTextView *)view
{
if(string != nil){
[[[view textStorage] mutableString] appendFormat:@"%@\n", string];
}
}
Apparently, your error must come from somewhere else than this
method, can you post some code where you call this method?
Cheers, Patrick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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