Skip to content

backends: Guard against NULL monitor mode during XRandR transitions#805

Open
appositeit wants to merge 1 commit intolinuxmint:masterfrom
appositeit:fix/null-monitor-mode-nvidia-xrandr
Open

backends: Guard against NULL monitor mode during XRandR transitions#805
appositeit wants to merge 1 commit intolinuxmint:masterfrom
appositeit:fix/null-monitor-mode-nvidia-xrandr

Conversation

@appositeit
Copy link

@appositeit appositeit commented Mar 4, 2026

Problem

NVIDIA drivers can report intermediate CRTC states with no valid mode during multi-monitor reconfiguration (e.g. when monitors wake from DPMS sleep). Several code paths dereference monitor->current_mode without NULL checks, causing a segfault in meta_monitor_mode_foreach_crtc when the mode's crtc_modes array is accessed through a NULL pointer.

Solution

Add NULL guards in four functions:

  • meta_logical_monitor_foreach_crtc() — skip monitors with no mode
  • calculate_monitor_scale() — return 1.0 as safe default
  • meta_monitor_manager_is_scale_supported_by_other_monitors() — skip
  • derive_scale_from_crtc() — return FALSE

Also reject screen sizes below 64px in meta_gpu_xrandr_read_current() as these indicate transient invalid states from the driver.

Add g_debug() logging around RRScreenChangeNotify processing to aid future diagnosis.

Testing

Tested on a single machine:

  • Ubuntu 25.10 (Cinnamon 6.4, muffin 6.4.1)
  • NVIDIA driver 570.133.07, proprietary
  • Dual monitor: 3440x1440 (DP) + 2560x1440 (HDMI)
  • DPMS sleep/wake cycling over multiple days with no segfaults

Previously this configuration would crash muffin within hours of enabling DPMS. With these guards, the NULL dereference crash path is eliminated.

This has only been tested on one machine and has not been widely tested.

Disclosure

This patch was developed with AI assistance (Claude Code). The code changes are minimal (NULL guards and a minimum size check) and have been manually reviewed.

Related issues

NVIDIA drivers can report intermediate CRTC states with no valid mode
during multi-monitor reconfiguration. Several code paths dereference
the monitor's current_mode without NULL checks, causing a segfault
in meta_monitor_mode_foreach_crtc when the mode's crtc_modes array
is accessed through a NULL pointer.

Add NULL guards in:
- meta_logical_monitor_foreach_crtc() — skip monitors with no mode
- calculate_monitor_scale() — return 1.0 as safe default
- meta_monitor_manager_is_scale_supported_by_other_monitors() — skip
- derive_scale_from_crtc() — return FALSE

Also reject screen sizes below 64px in meta_gpu_xrandr_read_current()
as these indicate transient invalid states from the driver.

Closes linuxmint#671
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.

muffin.so crashes in nvidia/cinnamon on monitor powerups from sleep

1 participant