diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 69d74058d63..93fe035336b 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -1636,9 +1636,20 @@ NS_METHOD nsWindow::Destroy() NS_IMETHODIMP nsWindow::SetParent(nsIWidget *aNewParent) { if (aNewParent) { + nsCOMPtr kungFuDeathGrip(this); + + nsIWidget* parent = GetParent(); + if (parent) { + parent->RemoveChild(this); + } + HWND newParent = (HWND)aNewParent->GetNativeData(NS_NATIVE_WINDOW); NS_ASSERTION(newParent, "Parent widget has a null native window handle"); - ::SetParent(mWnd, newParent); + if (newParent && mWnd) { + ::SetParent(mWnd, newParent); + } + + aNewParent->AddChild(this); return NS_OK; }