⚡ Sangsakala Proxy 🏠 Home
Skip to content

Fix crash on NaN DDC value after display reconfiguration - #1932

Open
Bouke wants to merge 1 commit into
MonitorControl:mainfrom
Bouke:fix/nan-ddc-value-crash
Open

Bouke wants to merge 1 commit into
MonitorControl:mainfrom
Bouke:fix/nan-ddc-value-crash

Conversation

@Bouke

@Bouke Bouke commented Oct 27, 2026

Copy link
Copy Markdown

When a display shows up under a new prefs id (after wake or re-docking, for example), setupCurrentAndMaxValues converts the DDC value it just read before maxDDC is stored. With min and max both 0, convDDCToValue divides 0 by 0 and the NaN gets saved as the current value. The next brightness change then traps on UInt16(NaN) in convValueToDDC; the min/max clamps don't help, as they pass NaN through.

This PR stores maxDDC before converting the read value. A display that reports a maximum of 0 falls back to DDC_MAX_DETECT_LIMIT (I've seen an iiyama do this for volume over HDMI), and a NaN that earlier versions already saved is removed, so the value is read again.

I reproduced it on 4.4.0 by removing the maxDDC keys from the prefs: every command logged Current internal value: nan and the next brightness key press crashed. With this change the same steps give valid values. Probably the same crash as #1919. #1874 also guards against min == max in the conversions, but doesn't cover the ordering or the NaN values already in people's prefs.

On first setup (or when a display reports a maximum of 0) the read value was converted using a maxDDC of 0, saving NaN to the prefs. Converting that back to a DDC value traps, crashing the app on the next brightness change.

Existing NaN prefs are removed on setup, so affected users recover without resetting their settings.
@waydabber

Copy link
Copy Markdown
Member

Thanks for the fix! The ordering change and NaN cleanup look good.

One small edge case: with minDDCOverride = 100 and a reported max of 80, the fallback sets maxDDC to 100 too. This still causes division by zero and saves NaN again. Could you make sure the final effective max is always greater than the min before converting?

Once this is fixed, I'll merge it. Thanks!

@Bouke

Bouke commented Nov 2, 2026

Copy link
Copy Markdown
Author

Good catch; any min override of 100 or more ended up there, as the detect limit also clips the reported max. The effective max is now forced above the min before saving.

This branch has not been deployed

No deployments
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.

2 participants