• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Appending string to NSTextView crashing app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 23:22:55 -0400

So, I have, at least I think, found the offending code. In the startAppButton function, if I even try to allocate an NSString object it crashes. I don't even have to send it to appendString function, this is why I'm not so sure this is the problem. But, if I change the startAppButton function to be:

- (IBAction)startAppButton:(id)sender
{
    [[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(appNotificationObserver:)
    name:nil object:nil];
}

It works like a charm. Odd. I feel like I'm missing something basic here...

--
Evan

On Apr 25, 2007, at 10:42 PM, Evan Moseman wrote:

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:
40gmail.com


This email sent to email@hidden

_______________________________________________

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


References: 
 >Appending string to NSTextView crashing app (From: Evan Moseman <email@hidden>)
 >Re: Appending string to NSTextView crashing app (From: Ryan Stevens <email@hidden>)
 >Re: Appending string to NSTextView crashing app (From: Evan Moseman <email@hidden>)
 >Re: Appending string to NSTextView crashing app (From: PGM <email@hidden>)
 >Re: Appending string to NSTextView crashing app (From: Evan Moseman <email@hidden>)

  • Prev by Date: Re: Appending string to NSTextView crashing app
  • Next by Date: Re: Appending string to NSTextView crashing app
  • Previous by thread: Re: Appending string to NSTextView crashing app
  • Next by thread: Re: Appending string to NSTextView crashing app
  • Index(es):
    • Date
    • Thread