Skip to content

fix: guard against null rect in Node.set rect - #541

Open
OddballGreg wants to merge 1 commit into
forge-ext:mainfrom
OddballGreg:fix/null-rect-guard-in-set-rect
Open

OddballGreg wants to merge 1 commit into
forge-ext:mainfrom
OddballGreg:fix/null-rect-guard-in-set-rect

Conversation

@OddballGreg

Copy link
Copy Markdown

Fixes the unhandled TypeError: rect is null reported in #540.

The bug

Node.set rect lets a WINDOW node hold a null rect, because that case breaks immediately and never touches an actor. split() then copies that value onto a freshly created CON node:

// tree.js:1120
newConNode.rect = node.rect;    // node is a WINDOW whose _rect is still null

The CON branch does dereference it, so set_size() throws:

JS ERROR: TypeError: rect is null
  set rect@.../lib/extension/tree.js:129:11
  split@.../lib/extension/tree.js:1120:5
  command@.../lib/extension/window.js:567:19
  trackWindow@.../lib/extension/window.js:1418:16
  trackCurrentWindows@.../lib/extension/window.js:1651:12
  _bindSignals/this._displaySignals<@.../lib/extension/window.js:211:18

Reached when auto-split-enabled is true (the default), since trackWindow issues a Split command before the new window has been through a renderTree pass and therefore before it has any geometry.

This matters more than a log line because the throw escapes a display workareas-changed handler, which runs while mutter is reconfiguring monitors and work areas. See #540 for the display-side symptoms I measured alongside it.

The change

-        if (this.actor) {
+        if (this.actor && rect) {

Guards the actor geometry calls rather than the assignment in split(), on the grounds that any caller can reach the setter with a null rect, so the setter is the right place to be defensive.

The node still records _rect = null. Only the two actor geometry calls are skipped, and the following renderTree assigns a real rect and sizes the actor, so there is no visual change.

Verification

  • Running this locally on GNOME Shell 46.0 / Wayland with a 3 monitor layout that reproduced the exception three times in one session. The exception is gone and tiling behaves normally.
  • Formatting checked against the pinned prettier@2 from package.json: the file is clean both before and after the change. (Note prettier@3 reports pre-existing issues in this file, unrelated to this PR, so I left them alone rather than bloat the diff.)
  • node --check passes.

A WINDOW node is allowed to hold a null rect, since its branch in the
setter breaks immediately and never touches an actor. split() then copies
that value onto a newly created CON node via `newConNode.rect = node.rect`,
and the CON branch does dereference it, so set_size() throws.

This surfaces as an unhandled `TypeError: rect is null` at tree.js:129,
reached from trackWindow() -> command("Split") -> split() when
auto-split-enabled is true and the window has not been through a
renderTree pass yet, so its rect is still unset.

The throw escapes a display "workareas-changed" handler, which runs while
mutter is reconfiguring monitors and work areas.

Guard the actor geometry calls instead of the assignment, since any caller
can reach the setter with a null rect. The node still records _rect = null
and the following renderTree assigns a real rect and sizes the actor, so
there is no visual change.

Refs forge-ext#540
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.

1 participant