WaylandBackend: prevent crash after closing window #1733
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This addresses two related issues around closing windows in the Wayland backend.
"Zombie windows":
When the last gamescope client closes, the wayland backend tries to
close the window until a new client appears. However, this is done in
the destructor for the connector for the window, which is stored in
a
shared_ptr
. Thisshared_ptr
was held by bothsteamcompmgr
(whichcorrectly dropped it) and by the wayland backend, which would never drop
it. This led to the first window being kept around as a "zombie window",
which would show the last frame from the previous client, but otherwise
never update (the backend would only hold a reference to the first
window, and no subsequent ones).
This fixes this issue by downgrading the
shared_ptr
held by the backendinto a
weak_ptr
. Thus, the only owning reference to the backend at(almost) any given point is held by
steamcompmgr
, which allows thewindow to be correctly closed when
steamcompmgr
drops it. This alsoallows for the connector held by the wayland backend to be updated when
a new window is created.
HACK: This is NOT memory-safe, and will result in a segmentation fault
if the connector held by the wayland backend is used (e.g., via
::GetCurrentConnector
) after it was dropped bysteamcompmgr
. The codealready included a TODO to remove the need for the backend to hold
a reference to the connection, and this is still necessary.
Crashing on window close:
Whenever a window was truly closed (i.e., not left behind as a zombie
window), gamescope would segfault due to calling
IsSurfacePlane
with null (fromWayland_Pointer_Leave
, and maybe a fewother places). This is addressed by having
IsSurfacePlane
short-circuitif it's passed null.
HACK: I feel like
IsSurfacePlane
shouldn't ever be called with a nullpointer, but this is the easiest way to solve this for now, and the code
needs refactoring anyway.
See also #1611 and #1456.