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:
parent
97e5a1969f
commit
e0fddcefb6
@ -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 );
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user