Commit f77eb3bb authored by Artur Grunau's avatar Artur Grunau
Browse files

MDI: fix a null pointer deref on window undocking

When a new floating MDI window was created, its position was tracked
from the very beginning. This caused the window's initial move event,
generated by the show() method, to be handled by the undocking
mechanism.

This event might contain outdated position information that, in certain
cases, could trigger immediate re-docking of the floating window,
setting its pointer to 0. If this happened, then the remaining code that
configured the floating window would dereference the null pointer and
crash the application.

To fix the error, connect the floating window's signals only after it
has been fully configured. This way its initial move events are ignored.
parent 8df4c5d0
...@@ -148,9 +148,6 @@ namespace campvis { ...@@ -148,9 +148,6 @@ namespace campvis {
_floatingWindow = new MdiFloatingWindow(widget, this); _floatingWindow = new MdiFloatingWindow(widget, this);
_floatingWindow->setWindowTitle(this->windowTitle()); _floatingWindow->setWindowTitle(this->windowTitle());
this->connect(_floatingWindow, SIGNAL(s_positionChanged(const QPoint&)),
SLOT(trackFloatingWindowPosition(const QPoint&)));
this->connect(_floatingWindow, SIGNAL(s_closed()), SLOT(handleWindowClosing()));
_dockedWindow->deleteLater(); _dockedWindow->deleteLater();
_dockedWindow = 0; _dockedWindow = 0;
...@@ -159,6 +156,16 @@ namespace campvis { ...@@ -159,6 +156,16 @@ namespace campvis {
_floatingWindow->show(); _floatingWindow->show();
_floatingWindow->activateWindow(); _floatingWindow->activateWindow();
_floatingWindow->forceWindowDrag(); _floatingWindow->forceWindowDrag();
/*
* Connect signals last so that the floating window's initial move events are ignored.
* They mustn't be handled because they may contain outdated position information which
* could, in extreme cases, trigger immediate re-docking of the floating window,
* leading to all sorts of problems.
*/
this->connect(_floatingWindow, SIGNAL(s_closed()), SLOT(handleWindowClosing()));
this->connect(_floatingWindow, SIGNAL(s_positionChanged(const QPoint&)),
SLOT(trackFloatingWindowPosition(const QPoint&)));
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment