RE: NSLayoutManagers
RE: NSLayoutManagers
- Subject: RE: NSLayoutManagers
- From: "Josh Ferguson" <email@hidden>
- Date: Mon, 12 Aug 2002 10:02:10 -0500
- Priority: normal
- Thread-topic: NSLayoutManagers
Charles,
As always, thanks for the tips! However, I think you're assuming that I'm adding layout managers manually, which I'm not. The text system is taking care of creating and adding the layout manager, and I'm simply swapping out the default text storage for my custom text storage. While I don't have a complete grasp on it, I believe that this is the appropriate situation for replaceTextStorage.
Josh
-----Original Message-----
From: Charles Jolley [
mailto:email@hidden]
Sent: Friday, August 09, 2002 7:19 PM
To: Josh Ferguson
Cc: Brian Webster; email@hidden
Subject: Re: NSLayoutManagers
Hi Josh:
Two things:
1. Whenever you get an exception where a message is being sent to some
weird object that doesn't belong in a collection it usually means that
somewhere along the line the object originally at the address in
question was dealloced and its heap space happens to have gone to
another object. Had this not happened, you would get an access
violation instead of the exception. I would start debugging this by
looking at places where I deal with memory management for layout
managers, especially if you are connecting more than one layout manager
to this text storage, even if only one is connected at a time.
2. I have always used replaceTextStorage only when I am replacing the
text storage for one or more layout managers. When I first setup the
text system chain, I connect the layout manager to the text storage
using NSTextStorage's -addLayoutManager:. I think that when everything
is working properly these could be used interchangeably for initial
setup. You might want to try using this alternative method to see if
it causes the problem to show up in a different way so you can track it
down.
When I do anything complicated with the text system, this is one of the
most common bugs that pop up for me during development because I'm
juggling so many different objects as the user goes about their
business.
Good Luck!
-C
On Friday, August 9, 2002, at 02:52 PM, Josh Ferguson wrote:
>
I don't think this is the case, but I'll explain later...first the
>
code I'm using:
>
>
...
>
[[textView layoutManager] replaceTextStorage:[[SyntextStorage alloc]
>
init]];
>
...
>
storage = [textView textStorage];
>
[self updateView];
>
[storage setDelegate:self];
>
...
>
>
When the app first opens a document (whether it be blank or filled
>
with text), the appropriate calls for fixAttributes are made, and the
>
layout manager array is filled with just one layout manager. As soon
>
as I type something into the text view, however, it calls
>
fixAttributes (appropriately), where I make the call to get the array
>
of layout managers, and that's when I get an invalid member. I
>
believe it's something rooted deeper in the text system than that.
>
>
Josh Ferguson
>
>
-----Original Message-----
>
From: Brian Webster [mailto:email@hidden]
>
Sent: Friday, August 09, 2002 2:41 PM
>
To: email@hidden
>
Cc: Josh Ferguson
>
Subject: Re: NSLayoutManagers
>
>
>
My first inclination is that something is going awry in the way
>
you're setting up your text system hierarchy. Like perhaps
>
you're calling -[NSLayoutManager setTextStorage:] instead of
>
-[NSLayoutManager replaceTextStorage:] or something like that.
>
Could you post the code where you do your setup?
>
>
On Friday, August 9, 2002, at 02:09 PM, cocoa-dev-
>
email@hidden wrote:
>
>
> I have some questions about the relationship between
>
> NSTestStorage and NSLayoutManagers. I have a pretty basic text
>
> editor in which I've implemented a concrete sub-class of
>
> NSTextStorage. In order to keep the coloring of the text up to
>
> date, I have chosen to send an
>
> invalidateDisplayForCharacterRange: message to the
>
> layoutmanager(s) from within the text storage. This seems
>
> pretty straight forward, as I just call [self layoutManagers]
>
> to create an array of layout managers. My first inclination
>
> was to place that in a for loop and send the message to every
>
> layout manager in the array. For some reason, however, the
>
> array is getting an invalid member, which is causing a run time
>
> error because "NSSubTextStorage" (which is NOT my subclass)
>
> does not respond to invalidateDisplayForCharacterRange. My
>
> answer to this is to simply send the message to the first
>
> layout manager. Does anyone know of any problems that might
>
> arise from just sending it to the first member of the array? !
>
> I don't have multiple layouts in my view, so I shouldn't
>
> actually have to worry about multiple layout managers, but the
>
> Cocoa text system is so cryptic that I'm never confident that
>
> it won't try and pull something on me behind the scenes ;).
>
> Also, does anyone have any clue why I'd be getting an invalid
>
> member in my layout manager array?
>
--
>
Brian Webster
>
email@hidden
>
http://homepage.mac.com/bwebster
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.