diff options
author | Roger Maclean <[email protected]> | 2014-12-04 16:28:42 -0500 |
---|---|---|
committer | Roger Maclean <[email protected]> | 2014-12-08 17:52:52 +0100 |
commit | 310fd3ed8c9978840b67231404cb3b4ba30193c2 (patch) | |
tree | 4ce2023918cdaf795216fc602cf5138a4481d017 /src/quick/scenegraph/qsgthreadedrenderloop.cpp | |
parent | 7fa4b8600be74c10c555ba07317e9b754f18ce3d (diff) |
Avoid inadvertent copies of the windows list
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 <[email protected]>
Diffstat (limited to 'src/quick/scenegraph/qsgthreadedrenderloop.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgthreadedrenderloop.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp index 5218552427..43cb6ab05c 100644 --- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -145,7 +145,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); @@ -943,9 +943,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) |