Salut,
   I got a crash while playing with new code and I wonder if we should fix
the view parenting code to avoid this. The problem happens when you try to
add a child view to a parent view that already has this view as a child.

Here's how it goes:

First we call AddChildView with an already child view pointer:
void View::AddChildView(View* v) {
  AddChildView(static_cast<int>(child_views_.size()), v, false);
}

the child_views_.size() value will include this child view...

void View::AddChildView(int index, View* v, bool floating_view) {
  // Remove the view from its current parent if any.
  if (v->GetParent())
    v->GetParent()->RemoveChildView(v);

  if (!floating_view) {
    // Sets the prev/next focus views.
    InitFocusSiblings(v, index);
  }
[...]

since the child view already has this view as a parent, it will be removed
as a child, which is fine... But now, the child_views_.size() value will be
decremented, and index is now too big...

Now I'm wondering, should we simply return if we recognize ourselves as the
current parent of the child we were given? Or at least assert that we are
NOT the current parent? Or just leave it like that and document that it can
NOT be called with an already child view?

Thanks!

BYE
MAD

--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected] 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to