Improve detection of attaching windows to more than one sizer.
It's not only an error to insert a window twice into the same sizer, it's already an error, and even a more insidious one, to insert it twice into different sizers, so guard against this as well as debugging it (much) later, when the window and the sizer is destroyed is much less fun.
This commit is contained in:
parent
31145b8e3a
commit
efce9b2306
@ -2476,12 +2476,21 @@ void wxWindowBase::SetSizerAndFit(wxSizer *sizer, bool deleteOld)
|
||||
|
||||
void wxWindowBase::SetContainingSizer(wxSizer* sizer)
|
||||
{
|
||||
// adding a window to a sizer twice is going to result in fatal and
|
||||
// hard to debug problems later because when deleting the second
|
||||
// associated wxSizerItem we're going to dereference a dangling
|
||||
// pointer; so try to detect this as early as possible
|
||||
wxASSERT_MSG( !sizer || m_containingSizer != sizer,
|
||||
wxT("Adding a window to the same sizer twice?") );
|
||||
// Adding a window to another sizer if it's already managed by one would
|
||||
// result in crashes later because one of the two sizers won't be notified
|
||||
// about the window destruction and so will use a dangling pointer when it
|
||||
// is destroyed itself. As such problems are hard to debug, don't allow
|
||||
// them to happen in the first place.
|
||||
if ( sizer )
|
||||
{
|
||||
// This would be caught by the check below too, but give a more clear
|
||||
// error message in this case.
|
||||
wxASSERT_MSG( m_containingSizer != sizer,
|
||||
wxS("Adding a window to the same sizer twice?") );
|
||||
|
||||
wxCHECK_RET( !m_containingSizer,
|
||||
wxS("Adding a window already in a sizer, detach it first!") );
|
||||
}
|
||||
|
||||
m_containingSizer = sizer;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user