Commit 94730634 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Improve readability of code that destroys frame callback resources

If a frame callback resource is destroyed, it will unregister itself
from corresponding lists in current, pending, and cached state.

However, this means that we need to be super duper careful when the
compositor wants to destroy all frame callbacks. We need to make a copy
of a frameCallbacks list; otherwise a call to removeOne() will
invalidate iterators and the compositor may crash.

Currently, that copy is made implicitly. Some people may see that code
and add qAsConst() without realizing the consequences it will lead to.

This change improves the readability of that code by making explicit
copies of frameCallbacks in code that shuts down SurfaceInterface.
parent cd2c13bd
......@@ -54,15 +54,22 @@ SurfaceInterfacePrivate::SurfaceInterfacePrivate(SurfaceInterface *q)
for (KWaylandFrameCallback *frameCallback : current.frameCallbacks) {
// Need a copy to avoid hitting invalidated iterators in the for loop.
const QList<KWaylandFrameCallback *> currentFrameCallbacks = current.frameCallbacks;
for (KWaylandFrameCallback *frameCallback : currentFrameCallbacks) {
for (KWaylandFrameCallback *frameCallback : pending.frameCallbacks) {
const QList<KWaylandFrameCallback *> pendingFrameCallbacks = pending.frameCallbacks;
for (KWaylandFrameCallback *frameCallback : pendingFrameCallbacks) {
for (KWaylandFrameCallback *frameCallback : cached.frameCallbacks) {
const QList<KWaylandFrameCallback *> cachedFrameCallbacks = cached.frameCallbacks;
for (KWaylandFrameCallback *frameCallback : cachedFrameCallbacks) {
if (current.buffer) {
Supports Markdown
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