Skip to content

Fix crash when clicking "restore" on monitor config

Jonas Ådahl requested to merge jadahl/mutter:wip/monitor-config-restore into main
monitor-manager: Restore old config in idle callback when unconfirmed

We might get told to restore the old monitor configuration by the
monitor configuration prompt, in case the user pressed "revert" or
equivalent. This might be in response to a button press, and those
happen during frame clock dispatch. If we would restore an old
configuration during dispatch, it means we would reconfigure the
monitors including their stage views while dispatching, which means we'd
destroy the frame clock while it's dispatching.

Doing that causes problems, as the frame clock isn't expecting to be
destroyed mid-function. Specifically,

We'd enter

  clutter_frame_clock_dispatch (clutter-frame-clock.c:811)
  frame_clock_source_dispatch (clutter-frame-clock.c:839)
  g_main_dispatch (gmain.c:3454)
  g_main_context_dispatch (gmain.c:4172)
  g_main_context_iterate.constprop.0 (gmain.c:4248)
  g_main_loop_run (gmain.c:4448)
  meta_context_run_main_loop (meta-context.c:482)
  main (main.c:663)

which would first call

  _clutter_process_event (clutter-main.c:920)
  _clutter_stage_process_queued_events (clutter-stage.c:757)
  handle_frame_clock_before_frame (clutter-stage-view.c:1150)

which would emit e.g. a button event all the way to a button press
handler, which would e.g. deny the new configuration:

  restore_previous_config (meta-monitor-manager.c:1931)
  confirm_configuration (meta-monitor-manager.c:2866)
  meta_monitor_manager_confirm_configuration (meta-monitor-manager.c:2880)
  meta_plugin_complete_display_change (meta-plugin.c:172)

That would then regenerate the monitor configuration and stage view
layout, which would destroy the old stage view and frame clock.

  meta_stage_native_rebuild_views (meta-stage-native.c:68)
  meta_backend_native_update_screen_size (meta-backend-native.c:457)
  meta_backend_sync_screen_size (meta-backend.c:266)
  meta_backend_monitors_changed (meta-backend.c:337)
  meta_monitor_manager_notify_monitors_changed (meta-monitor-manager.c:3595)
  meta_monitor_manager_rebuild (meta-monitor-manager.c:3683)
  meta_monitor_manager_native_apply_monitors_config (meta-monitor-manager-native.c:343)
  meta_monitor_manager_apply_monitors_config (meta-monitor-manager.c:704)

After returning back to the original clutter_frame_clock_dispatch()
frame, various state in the frame clock will be gone and we'd crash.

I don't know why we haven't seen this on GNOME 43 already.

Merge request reports