fix(brightness): guard against null screen reference during disconnect - #193
Open
xdvi wants to merge 2 commits into
Open
fix(brightness): guard against null screen reference during disconnect#193xdvi wants to merge 2 commits into
xdvi wants to merge 2 commits into
Conversation
xdvi
force-pushed
the
fix/brightness-null-screen
branch
from
July 2, 2026 19:30
45aa88d to
bf02233
Compare
The optional-chaining guard stops the TypeError flood, but doesn't address why it happened: monitors was a binding that recreated a BrightnessMonitor for every screen on each Quickshell.screens change, leaking the previous set (never destroyed, still parented to root, Timers/Behaviors still running) since none of them get destroy()ed. Each subsequent screen change added more zombies reacting to a dead screen reference, which is what actually drove CPU/memory up. Reconcile against the live screen list instead: reuse existing monitors for screens that are still connected, and destroy() the ones whose screen went away.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes a bug where disconnecting a monitor (e.g., when the screens are powered off by
swayidleduring idle) causes a flood ofTypeError: Cannot read property 'model' of nullwarnings inBrightness.qml, leading to 100% CPU usage, memory leaks, and processes being killed by the OOM killer.By adding optional chaining (
screen?.model), we safely handle cases where the screen reference becomes null during destruction.Root cause and the actual leak
The optional chaining stops the crash, but not the leak itself.
monitorswas a binding that recreated aBrightnessMonitorfor every screen on everyQuickshell.screenschange — the previous set of monitor objects was never destroyed (no.destroy()), just orphaned while still parented toroot, with theirTimer/Behavior/Processstill alive. Each screen connect/disconnect added another batch of zombie objects reacting to a deadscreenreference, which is what actually drove CPU and memory up over time, not a single error.Fixed by reconciling
monitorsagainst the live screen list instead of rebuilding it from scratch: screens that are still connected keep their existingBrightnessMonitor, and monitors whose screen went away are explicitlydestroy()ed.Testing
inir restart && inir logs— no errorsniri msg outputsthat the screen list actually changed, not just DPMSTypeError/ReferenceErrorduring or after the disconnect/reconnect cycleqt.qml.listvalueconversionwarning appears in both versions, confirming it's a pre-existing Quickshell/Qt quirk unrelated to this change, not a regression