Fix crash when logical monitor is null#12
Conversation
The get_work_area_current_monitor(), get_work_area_all_monitors(), and get_work_area_for_monitor() methods can trigger a fatal assertion in Mutter's meta_window_get_work_area_for_logical_monitor() if the window's logical monitor is null or invalid. This can occur during: - Monitor hotplug (connecting/disconnecting displays) - Display configuration changes - Windows in transient states between monitors The assertion failure causes GNOME Shell to abort, crashing the entire desktop session. This commit wraps the work area calls in a helper function that catches any errors and returns null instead, preventing the crash.
|
I successfully tested this fix by unplugging my monitor while polling the focused window, causing a crash. Then I restarted my GNOME session with my fork of the extension activated, repeated the experiment of unplugging my monitor, and the crash did not occur. |
The previous try/catch approach doesn't work because Mutter's assertion failure calls abort() at the C level, which terminates the process immediately and cannot be caught by JavaScript exception handling. Instead, we now check if the window has a valid monitor (index >= 0 and within bounds) BEFORE calling the get_work_area_* methods. If the monitor is invalid, we return null for those fields instead of crashing.
|
Note AI Assistance Disclosure: This comment was created with assistance from Claude Opus 4.5 via Cursor. Update: try/catch approach doesn't workAfter deploying the try/catch fix, GNOME Shell still crashed with the same assertion failure. The crash occurred at line 19 of the patched extension (inside the Root cause: Mutter's assertion failure calls I've pushed an updated fix that checks if the window has a valid monitor before calling the work area methods, rather than trying to catch the error afterward: function hasValidMonitor(metaWindow) {
const windowMonitor = metaWindow.get_monitor();
if (windowMonitor < 0) {
return false;
}
const numMonitors = global.display.get_n_monitors();
if (windowMonitor >= numMonitors) {
return false;
}
return true;
}If the monitor is invalid, the |
|
Thanks! |
Note
AI Assistance Disclosure: This PR was created with assistance from Claude Opus 4.5 via Cursor. The crash analysis, diagnosis, and fix were AI-assisted based on actual crash logs from my system.
Summary
Fixes #11
The
get_work_area_current_monitor(),get_work_area_all_monitors(), andget_work_area_for_monitor()methods can trigger a fatal assertion in Mutter'smeta_window_get_work_area_for_logical_monitor()if the window's logical monitor is null or invalid.This can occur during:
The assertion failure causes GNOME Shell to abort, crashing the entire desktop session.
Changes
This PR wraps the work area calls in a helper function
safeGetWorkArea()that catches any errors and returnsnullinstead, preventing the crash.Testing
I experienced this crash on my system (GNOME Shell 49.2, NixOS). Unfortunately I cannot easily test the fix without waiting for another crash to occur naturally, but the change is minimal and defensive—it simply wraps the existing calls in try/catch blocks.
Crash Log (for reference)