Skip to content

Commit

Permalink
Avoid inadvertent copies of the windows list
Browse files Browse the repository at this point in the history
There are a couple of ways in which this code creates
temporary copies of the window list, m_windows.  This is often
benign but there are also places (e.g. startOrStopAnimationTimer)
which get non-const references to items which results
in m_windows being detached from the temporary resulting in a real
copy of the list items.  Again the copy is often fairly benign,
however, as the code also relies heavily on pointers to items
in the list, it can also result in crashes.

I think it might be advisable to store a list of pointers to
Window structures rather than store the structure themselves as
it appears really easy to introduce copies of the list accidentally.
The removal of the use of foreach for example is not made here for
aesthetics but because it introduces a hidden temporary copy of
the list.

Change-Id: I504951a897c4fb0cf106f5a4792b5cfcd532ba8f
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
  • Loading branch information
Roger Maclean authored and sletta committed May 24, 2016
1 parent 352acf5 commit d47a01a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/quick/scenegraph/qsgthreadedrenderloop.cpp
Expand Up @@ -154,7 +154,7 @@ const QEvent::Type WM_TryRelease = QEvent::Type(QEvent::User + 4);
// called.
const QEvent::Type WM_Grab = QEvent::Type(QEvent::User + 5);

template <typename T> T *windowFor(const QList<T> list, QQuickWindow *window)
template <typename T> T *windowFor(const QList<T> &list, QQuickWindow *window)
{
for (int i=0; i<list.size(); ++i) {
const T &t = list.at(i);
Expand Down Expand Up @@ -953,9 +953,9 @@ void QSGThreadedRenderLoop::handleObscurity(Window *w)
void QSGThreadedRenderLoop::handleUpdateRequest(QQuickWindow *window)
{
qCDebug(QSG_LOG_RENDERLOOP) << "- polish and sync update request";
foreach (const Window &w, m_windows)
if (w.window == window)
polishAndSync(const_cast<Window *>(&w));
Window *w = windowFor(m_windows, window);
if (w)
polishAndSync(w);
}

void QSGThreadedRenderLoop::maybeUpdate(QQuickWindow *window)
Expand Down

0 comments on commit d47a01a

Please sign in to comment.