Skip to content

window: release stray item references to a window before deleting it - #1442

Open
afonsojramos wants to merge 1 commit into
quickshell-mirror:masterfrom
afonsojramos:window-release-references
Open

afonsojramos wants to merge 1 commit into
quickshell-mirror:masterfrom
afonsojramos:window-release-references

Conversation

@afonsojramos

Copy link
Copy Markdown

Describe your changes

Quickshell segfaults when my only monitor disconnects (same stack, but not sure it is the same, as #1340: derefWindow() from setParentItem() while a PanelWindow is destroyed).

The cause was a window reference that Qt leaks. When an inline ShaderEffectSource gets its sourceItem before it has a window (e.g. inside an asynchronous Loader), Qt refs the source item's window twice and releases it once. When the compositor closes the surface, Quickshell detaches the content and deletes the window, but that item keeps pointing at the deleted window, and destroying the PanelWindow later crashes on it.

This change releases any references that items in the content still hold on a window right before Quickshell deletes it.

Details and descisions

  • It only runs when the window is deleted, not in disownWindow(), because a window that is reused can still be legitimately referenced by things outside the content tree.
  • Releasing a reference emits windowChanged, and a handler could delete items, so the walk guards the item and its children with QPointer.
  • I reproduced it in a nested KWin with a small config (hide, show, hide, then destroy a PanelWindow with this pattern): stock 0.3.2 crashes every run, and the patched build doesn't.

Open concerns

  • This seems to work around a Qt bug in QQuickShaderEffectSource::setSourceItem. I'll investigate this over the next couple of days.
  • An effect parented directly to the backing window's contentItem() is outside the walked tree and isn't covered, but that requires _backingWindow, and it crashes without this change too.

Participation

I have this patched locally and have seen no further crash, so I'd like to see this through and can address review comments.

@afonsojramos
afonsojramos force-pushed the window-release-references branch from 1181261 to 473febb Compare November 9, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant