Skip to content

MultitaskingView: Fix crash when the primary monitor index becomes invalid - #2976

Closed
calderov wants to merge 2 commits into
elementary:mainfrom
calderov:fix-multitasking-invalid-monitor-crash
Closed

calderov wants to merge 2 commits into
elementary:mainfrom
calderov:fix-multitasking-invalid-monitor-crash

Conversation

@calderov

@calderov calderov commented Nov 16, 2026 •

Copy link
Copy Markdown

Fixes #2977

Issue:

Logging into a Wayland session on a laptop with an external monitor set as the primary display and both screens enabled makes Gala save the primary monitor's monitor_index in each workspace's FramedBackground, the framed wallpaper shown behind each workspace in the multitasking view.

However, if the laptop lid is closed and its screen is turned off, Mutter renumbers the remaining monitors, making the index saved in Gala outdated as it points to a monitor that no longer exists. When the background is rebuilt for the new monitor layout, it uses that outdated index to ask Mutter for the monitor's size. Mutter rejects it and leaves the size uninitialized, so the background ends up with a garbage size.

Since the ShadowEffect drawn around the background relies on its size to allocate a texture for the shadow, opening the multitasking view with a garbage size can crash the session.

Fix

This change fixes the issue by making the workspace backgrounds in the multitasking view (FramedBackground) follow the primary display. Their monitor_index is now settable and is updated whenever Mutter reports a monitor change. As safety nets, the background no longer uses the size of a monitor index that doesn't exist, and ShadowEffect skips drawing the shadow for sizes it can't handle instead of crashing the session.

Changes

  • BackgroundManager: monitor_index is now settable. Changing it rebuilds the background actor, and the geometry of an invalid monitor index is never used (no size, position or rounded clip from an uninitialized rect).
  • FramedBackground: follows the primary monitor on monitors-changed and keeps its shadow's monitor_scale in sync.
  • ShadowEffect: skips drawing the shadow when the size is non-positive, too small for the corner loops (< 2 * (shadow_size + border_radius)) or larger than 16384, instead of writing out of bounds.

Testing

calderov and others added 2 commits November 15, 2026 21:28
…valid

FramedBackground captured the primary monitor index once at construction.
When the monitor layout changes afterwards (e.g. closing a laptop lid with
an external monitor attached) the stored index can point to a monitor that
no longer exists. meta_display_get_monitor_geometry () then fails its
precondition and leaves the out rect uninitialized, so the workspace
background got a garbage size and ShadowEffect crashed while allocating
and filling a texture for it when opening the multitasking view.

- BackgroundManager: make monitor_index settable, rebuild the background
  when it changes and never use the geometry of an invalid monitor.
- FramedBackground: follow the primary monitor on monitors-changed.
- ShadowEffect: skip drawing the shadow for sizes the texture generation
  can't handle instead of writing out of bounds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lenemter

Copy link
Copy Markdown
Member

Using LLMs for coding goes against our contributor guide here: https://docs.elementary.io/contributor-guide/development/generative-ai-policy

@lenemter lenemter closed this Nov 16, 2026
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.

Session crash: Multitasking view causes session crash when the primary monitor index becomes invalid

2 participants