Re: Crash while adding to NSTextView

2011-02-02 Thread Mark Allan
On 3 Feb 2011, at 00:36, Kyle Sluder wrote:
> On Wed, Feb 2, 2011 at 4:12 PM, Mark Allan  
> wrote:
>>[consoleTextView replaceCharactersInRange:endRange 
>> withString:newText]; /**/ crashes here
> 
> You didn't call -shouldChangeTextInRange:replacementString: first, or
> call -didChangeText when you were done.
> 
> When working with the text system, it's important to remember to check
> both the NSText and NSTextView documentation. The text system is quite
> possibly the most confusing part of Cocoa.

Thanks very much, Kyle.  I'll go back and read the documentation again - 
properly this time!  I assumed that the "shouldChangeTextInRange" delegate 
method was something called automatically by the AppKit framework and that I 
didn't have to worry about it.  Apple's sample code ('log' method on the URL 
below) on the developer documentation website doesn't have those calls either, 
so that pretty much cemented my misunderstanding.
http://tinyurl.com/BaseWindowController-m

Thanks again for setting me straight.

Mark
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Crash while adding to NSTextView

2011-02-02 Thread Kyle Sluder
On Wed, Feb 2, 2011 at 4:12 PM, Mark Allan  wrote:
>        [consoleTextView replaceCharactersInRange:endRange 
> withString:newText]; /**/ crashes here

You didn't call -shouldChangeTextInRange:replacementString: first, or
call -didChangeText when you were done.

When working with the text system, it's important to remember to check
both the NSText and NSTextView documentation. The text system is quite
possibly the most confusing part of Cocoa.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Crash while adding to NSTextView

2011-02-02 Thread Mark Allan
Hi all,

I've got an intermittent crash which occurs when adding an NSString to an 
NSTextView in my app's main window.  I very rarely experience the crash myself, 
but a relatively high number of users have reported it to me.

It finally happened to me while running the app from Xcode tonight, so I've got 
a chance to debug it, but I can't see what's going wrong.

The debugger console says:

Program received signal:  “EXC_BAD_ACCESS”.

Here's how the stack looks:
_NSLayoutTreeMoveToGlyphIndex
_NSLayoutTreeLineFragmentRectForGlyphAtIndex
-[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:]
-[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:]
-[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:]
-[NSTextStorage processEditing]
-[NSTextStorage endEditing]
-[AppController appendToConsole:]

Here's the relevant piece of code which is pretty much straight from Apple's 
sample code:
-(void) appendToConsole:(NSString *)newText{
NSRange endRange;
endRange.location = [[consoleTextView textStorage] length];
endRange.length = 0;
[consoleTextView replaceCharactersInRange:endRange withString:newText]; 
/**/ crashes here
endRange.length = [newText length];
[consoleTextView scrollRangeToVisible:endRange];
}

The consoleTextView is defined in my header file as IBOutlet NSTextView 
*consoleTextView and I make no attempts to alloc/release/retain it anywhere in 
the application.

Printing the 'newText' object in the debugger console prints out the text I'm 
expecting to see (which in this case is just a carriage return), so I'm 
confident that's not where the problem lies.  Possibly relevant is that the 
text from the previous call to this method hadn't yet appeared in the 
NSTextView before the crash happened.

Does anyone have any ideas what the cause might be?

I've got other stuff to work on, so I'm going to leave it running/paused in the 
debugger in case anyone's got any questions or any suggestions I can try which 
might point me in the right direction - I'm not sure when I'll be able to get 
it back into this state!

Many thanks
Mark
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com