discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible bug with adding subviews?


From: Stephen Brandon
Subject: Re: Possible bug with adding subviews?
Date: Tue, 12 Feb 2002 23:18:33 +0000

On Tuesday 12 Feb 2002 7:33 pm, Richard Frith-Macdonald wrote:

> > - during the unarchiving of "a" (superview "box" is decoded, then
> > [superview
> > addSubview:self] is called)
> >
> > The exception is thrown in -[NSView addSubview:], where the box's
> > _content_view object is asked to add *itself*, since _content_view ==
> > "a":
> >
> > if ([self isDescendantOf: aView]) {...   (throws exception)
> >
> >
> > I'm not sure where the best place to fix this is. Should the unarchiver
> > do a
> > check to see if the superview's contentview equals itself? (but then the
> > superview would never add the view to its subview list). Or should
> > NSView
> > just do a check to see if a view is adding itself as a subview, and
> > silently
> > ignore it?
>
> It sounds to me like there is an error in the decoder ... the NSView
> decoder
> is setting the subviews, then the NSBox specific code is setting the
> content
> view ... which adds it as a subview ... but it's already there.

Actually it's the other way around - the NSView decoder does the following:

 (1) unarchives superview (NSBox in our case)
   (a) NSBox unarchives its contentview (is this circular?)
   (b) NSBox sets contentview as its contentView, thus also adding it to its 
subviews
 (2) [superview addSubview:self]; // tries to get NSBox's contentview to add 
self as a subview, but self is already the contentview and raises.
 (3) subviews = [unarchiver decodeObjectWithName:@"subviews"];
 (4) for (i = 0, count = [subviews count]; i < count; i++)
    [self addSubview:[subviews objectAtIndex:i]]; //this is ok

So perhaps in step (2) we can check with the superview as to whether "self" 
is already one of its subviews, or indeed is already its _content_view, and 
not try to add itself if this is the case.

How does that sound?


> There are three places it could be fixed ...
> 1. in the gmodel NSBox decoder
> 2. in the NSBox setContentView: method
> 3. in the NSView addSubview: method
>
> I think 1 is almost certainly the correct place to change.

What I'm suggesting is in the gmodel NSView decoder.

Cheers,
Stephen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]