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: Tue, 24 Apr 2007 23:24:56 -0400
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];
}
But, it is still crashing at the same point. I'm trying to read
info. from the debugger, but something looks wrong there as well:
[Switching to process 3426 local thread 0xf03]
Running…
Pending breakpoint 1 - "-[NSException raise]" resolved
Program received signal: "EXC_BAD_ACCESS".
Unable to restore previously selected frame:
Unable to restore previously selected frame:
Unable to restore previously selected frame:
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSApplicationWillUpdateNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextStorageWillProcessEditingNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextStorageDidProcessEditingNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextViewDidChangeTypingAttributesNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextViewDidChangeSelectionNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSWindowDidUpdateNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextStorageWillProcessEditingNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextStorageDidProcessEditingNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSApplicationDidUpdateNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextStorageWillProcessEditingNotification
2007-04-24 23:22:59.189 Notification System[3426] app note:
NSTextStorageDidProcessEditingNotification
Cannot access memory at address 0x4
Cannot access memory at address 0x4
Unable to disassemble objc_msgSend_rtp.
--
Evan
On Apr 24, 2007, at 11:16 PM, Ryan Stevens wrote:
- (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];
}
You don't need to make the text view editable to add to its
textStorage. You do need to release what you alloc/init - read up
on memory management. I got rid of the subString which should've
been released as well - appending is more logical and is likely
faster than initWithFormat: anyway.
Hope that helps.
On Apr 24, 2007, at 7:29 PM, Evan Moseman wrote:
I'm hoping somebody can help me with this, I'm trying to append
text to an NSTextView using this function:
- (void)appendString:(NSString *)string toView:(NSTextView *)view
{
if (string == nil) { return; }
[view setEditable:YES];
NSString *subString = [[NSString alloc] initWithFormat:@"%@\n",
string];
NSAttributedString *stringToAppend =
[[NSAttributedString alloc] initWithString:subString];
[[view textStorage] appendAttributedString:stringToAppend];
[view setEditable:NO];
}
But, after about 10 strings, the whole app crashes with a seg
fault. I can print the strings using NSLog and it never crashes.
Is there something wrong with the above code? Should I try using
bindings?
Any help is greatly appreciated!
Thanks!
--
Evan
_______________________________________________
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