🐞 Fix stack overflow crash on window-move actions#1113
Merged
mrkai77 merged 1 commit intoJul 1, 2026
Conversation
Window-move actions (moveUp/Down/Left/Right) crashed Loop with EXC_BAD_ACCESS (stack overflow). In WindowFrameResolver.calculateTargetFrame, the `willMove` branch read `context.getTargetFrame()`, whose lazy recompute calls `WindowFrameResolver.getFrame` on the *same* ResizeContext, which re-enters the willMove branch — infinite mutual recursion until the stack guard page is hit. Fix the willMove branch to read `lastAppliedFrame ?? cachedTargetFrame.raw`, matching the grow/shrink branches. This removes the self-recursion at its source and anchors moves to the window's actual position instead of a theoretical (possibly clamped-away) target frame. Also harden ResizeContext.recomputeTargetFrame to clear its `needsRecompute` guard before resolving, so any future re-entrant getTargetFrame() returns the cached frame instead of recursing.
mrkai77
approved these changes
Jul 1, 2026
mrkai77
left a comment
Owner
There was a problem hiding this comment.
I was able to reproduce the issue locally, and this PR fixes it. Thanks :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Window-move actions (
moveUp/moveDown/moveLeft/moveRight) crash Loop withEXC_BAD_ACCESS(stack overflow) as soon as they're triggered — via a keybind, the radial-menu preview, or aloop://direction/Move…URL.Root cause
WindowFrameResolver.calculateTargetFrame(...)resolves thewillMovebranch by readingcontext.getTargetFrame().ResizeContext.getTargetFrame()lazily callsrecomputeTargetFrame(), which callsWindowFrameResolver.getFrame(resizeContext: self)on the same context — re-entering thewillMovebranch and callinggetTargetFrame()again. SinceneedsRecomputeis only cleared at the end ofrecomputeTargetFrame(), the re-entrant call recomputes again → infinite mutual recursion → stack overflow.Crash backtrace (abridged):
Fix
WindowFrameResolver.swift— thewillMovebranch now readslastAppliedFrame ?? cachedTargetFrame.raw(matching the grow/shrink branches) instead ofgetTargetFrame(). This removes the self-recursion at its source, and anchors moves to the window's actual position rather than a theoretical, possibly clamped-away target frame (also fixing move drift on size-constrained windows).ResizeContext.swift(defensive) —recomputeTargetFrame()clearsneedsRecomputebefore resolving, so any future re-entrantgetTargetFrame()returns the cached frame instead of recursing. Not strictly required after the resolver change; happy to drop it if you'd prefer a minimal one-file diff.Testing
Before:
open "loop://direction/MoveLeft"on a focused window → immediateEXC_BAD_ACCESScrash with the recursion backtrace above.After: same trigger (MoveLeft + MoveRight) → resolver computes the frame, the window moves, action recorded, no crash:
swiftformat --lintis clean; built with theLoopscheme (Release).