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 <laszlo.agocs@theqtcompany.com>
This commit is contained in:
parent
7fa4b8600b
commit
310fd3ed8c
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue