Catch attempts to create a window with itself as parent.

This doesn't happen often but when it does, the results are catastrophic and
not always easy to debug, so try catch this as soon as possible.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73139 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2012-12-08 00:37:10 +00:00
parent 97e5a1969f
commit e0fddcefb6
2 changed files with 15 additions and 1 deletions

View File

@ -752,7 +752,7 @@ public:
bool IsDescendant(wxWindowBase* win) const;
// it doesn't really change parent, use Reparent() instead
void SetParent( wxWindowBase *parent ) { m_parent = (wxWindow *)parent; }
void SetParent( wxWindowBase *parent );
// change the real parent of this window, return true if the parent
// was changed, false otherwise (error or newParent == oldParent)
virtual bool Reparent( wxWindowBase *newParent );

View File

@ -1317,6 +1317,20 @@ void wxWindowBase::RemoveChild(wxWindowBase *child)
child->SetParent(NULL);
}
void wxWindowBase::SetParent(wxWindowBase *parent)
{
// This assert catches typos which may result in using "this" instead of
// "parent" when creating the window. This doesn't happen often but when it
// does the results are unpleasant because the program typically just
// crashes when due to a stack overflow or something similar and this
// assert doesn't cost much (OTOH doing a more general check that the
// parent is not one of our children would be more expensive and probably
// not worth it).
wxASSERT_MSG( parent != this, wxS("Can't use window as its own parent") );
m_parent = (wxWindow *)parent;
}
bool wxWindowBase::Reparent(wxWindowBase *newParent)
{
wxWindow *oldParent = GetParent();