Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
(fix) Linux: popping out the piano roll no longer crashes the app (#83)
Egor Khindikaynen1472e62a6565
diff --git a/.specify/bugs/linux-detail-window-crash/assessment.md b/.specify/bugs/linux-detail-window-crash/assessment.mdnew file mode 100644index 00000000..76eaf282--- /dev/null+++ b/.specify/bugs/linux-detail-window-crash/assessment.md@@ -0,0 +1,122 @@+# Bug Assessment: Linux — app aborts when the piano roll is popped out into its own window++- **Slug**: linux-detail-window-crash+- **Created**: 2026-10-15+- **Source**: pasted text (screenshot of a terminal stack trace + a video description from a tester on Fedora)+- **Verdict**: valid+- **Severity**: high++## Report (verbatim or summarized)++A tester on Fedora Linux runs the Nota AppImage (`/tmp/.mount_Nota-…/usr/bin/Nota.App`), tries to open the+piano roll in a separate window, and the app crashes. The terminal shows:++```+#0 __pthread_kill_implementation (libc.so.6)+#1 raise (libc.so.6)+#2 abort (libc.so.6)+#3–#8 libcoreclr.so+#9–#18 n/a (n/a + 0x0) ← JIT-compiled managed frames+#19–#24 libcoreclr.so+#25–#29 libhostpolicy.so / libhostfxr.so+#30–#34 Nota.App / __libc_start_main+```++The tester's log (`~/.config/nota/logs/nota-20261015.log`) then gave the managed exception:++```+2026-10-15T07:46:34.692Z ERROR Unhandled exception+System.ArgumentException: Attempt to call InvalidateArrange on wrong LayoutManager.+ at Avalonia.Layout.LayoutManager.ExecuteArrangePass()+ at Avalonia.Layout.LayoutManager.ExecuteLayoutPass()+ at Avalonia.Media.MediaContext.FireInvokeOnRenderCallbacks()+ at Avalonia.Media.MediaContext.RenderCore()+ ...+ at Avalonia.X11.X11PlatformThreading.RunLoop(CancellationToken cancellationToken)+ ...+ at Nota.App.Program.Main(String[] args)+```++## Symptom++Opening the detached Devices / Clip window (piano roll on top, device chain below) kills the process on+Linux. Expected: the window opens with the current clip editor and device chain, as on macOS/Windows.++## Reproduction++1. Launch the Nota AppImage on Fedora [NEEDS CLARIFICATION: Nota version, Fedora version, X11 or Wayland/XWayland, desktop (GNOME/KDE)].+2. Open or create a project with a MIDI clip [NEEDS CLARIFICATION: was a clip selected / the piano roll already open docked?].+3. Pop the detail panel out (View → pop out Devices/Clip, command `view.popOutDetail`) [NEEDS CLARIFICATION: exact action used — menu, shortcut or button].+4. Process aborts.++## Suspected Code Paths++- `src/managed/Nota.App/MainWindow.DetailWindow.cs:SetHost()` / `OnToggleDetailWindow()` — moves the live+ `_deviceChain` and clip editor out of the main window's `DetailBody` into the new `DetailWindow` hosts,+ with layout work for those controls still queued in the **main window's** `LayoutManager`.+- `src/managed/Nota.App/MainWindow.Mixer.cs:45` — the mixer pop-out does the same (and sets+ `_mixer.IsVisible = true` *while still in the main tree*, which queues it in the main window's layout+ manager right before moving it). Same crash expected on Linux.+- `src/managed/Nota.App/DetailWindow.cs:OnClosing` and `MixerWindow.cs:OnClosing` — the reverse move+ (re-dock); lower risk because the closing window's layout manager is disposed, but same pattern.+- Avalonia 12.0.3 `src/Avalonia.Base/Layout/LayoutManager.cs` — `ExecuteArrangePass()` → `Arrange()` walks up to+ the control's (new) root, finds an ancestor whose measure is invalid (`AncestorMeasureInvalid`), adds the+ control to `_toArrangeAfterMeasure`, then calls `InvalidateArrange(i)`, which throws because+ `control.GetLayoutRoot() != _owner`.++## Root Cause Hypothesis++Every `TopLevel` has its own `LayoutManager` with its own measure/arrange queues, and Avalonia never removes a+control from a queue when it is reparented. The detail panel's controls are invalidated constantly (meters,+playhead, tick loop), so at pop-out time some of them sit in the main window's queues. `OnToggleDetailWindow`+then moves them into `DetailWindow`. On the next render the main window's arrange pass dequeues such a+control, walks up into the *new* window, finds that window not yet measured, and re-queues the control via+`InvalidateArrange` on the main window's manager. Avalonia rejects that and throws `ArgumentException`. Nothing+catches it on the dispatcher, so the process aborts.++Why Linux: it depends on timing. On X11 mapping a window is asynchronous, and the WM's+`ConfigureNotify` (final size / centring / scaling) invalidates the new root's measure after `Show()`. So when+the main window's pass runs, the new window's ancestors are measure-invalid. On macOS/Windows the new window+is usually laid out synchronously before that, so `Arrange()` succeeds. The bug is cross-platform in+principle. **Confidence: high** for the mechanism (it matches the Avalonia source line for line), medium for+the exact reason it shows up only on X11.++## Proposed Remediation++**Preferred**: Flush the source window's layout queue before moving a control to another top-level. In+`SetHost`, when `content`'s current `TopLevel` differs from `host`'s, call `sourceTopLevel.UpdateLayout()`+before detaching (this runs `ExecuteLayoutPass` and empties the queues while the control is still in its old+tree). Any invalidation after the move goes to the new window's manager. That covers both the detail and the+mixer pop-out through one helper. In `MainWindow.Mixer.cs`, move `_mixer.IsVisible = true` after `SetHost`+(or rely on the flush). In `DetailWindow.OnClosing` / `MixerWindow.OnClosing`, call `UpdateLayout()` before+`Content = null`, for symmetry on re-dock.++**Alternatives**:+- Build the window and reparent inside `win.Opened` (after the first layout). Narrows the window but doesn't+ remove the race: the main queue can still hold the moved controls.+- `Dispatcher.UIThread.UnhandledException` → log + `Handled = true`. Stops the abort but leaves layout in a+ bad state. Fine as a separate safety net, not as the fix.++**Files likely to change**:+- `src/managed/Nota.App/MainWindow.DetailWindow.cs` (`SetHost`)+- `src/managed/Nota.App/MainWindow.Mixer.cs`+- `src/managed/Nota.App/DetailWindow.cs`, `src/managed/Nota.App/MixerWindow.cs` (`OnClosing`)+- a headless UI test under `tests/`++**Tests to add or update**:+- Avalonia.Headless: host a control in window A, `InvalidateArrange` it (and an ancestor's measure), move it+ into a new, not-yet-laid-out window B with `SetHost`, then run the render/layout pass. Without the fix it+ should throw the same `ArgumentException`; with the fix it should not.+- Pop out / re-dock detail and mixer during playback (meters invalidating) without a crash; manual check on+ Linux X11 (Fedora tester) is the real confirmation.++## Risks & Considerations++- Headless tests run on macOS won't exercise the X11/AT-SPI back end; a real Linux run is needed to confirm.+- Re-docking after a partial failure must not leave a control with two parents (see `SetHost`).+- Crash recovery should already offer the autosave on relaunch; confirm the tester didn't lose work.++## Open Questions++- [NEEDS CLARIFICATION: does the mixer pop-out crash on the tester's machine too? (expected: yes)]+- [NEEDS CLARIFICATION: X11 or XWayland session — the trace shows the X11 backend either way]diff --git a/.specify/bugs/linux-detail-window-crash/fix.md b/.specify/bugs/linux-detail-window-crash/fix.mdnew file mode 100644index 00000000..59032009--- /dev/null+++ b/.specify/bugs/linux-detail-window-crash/fix.md@@ -0,0 +1,75 @@+# Bug Fix: Linux — app aborts when the piano roll is popped out into its own window++- **Slug**: linux-detail-window-crash+- **Fixed**: 2026-10-15+- **Assessment**: ./assessment.md+- **Status**: applied++## Summary++When a control moves into another window, the old window's pending layout now runs between the+detach and the attach. Before, entries for the piano roll / device chain controls stayed in the main+window's layout queue after they had moved into `DetailWindow`. A later frame could then re-queue+them on the wrong `LayoutManager`, and Avalonia threw `ArgumentException`, which aborted the process.++## Changes++| File | Change | Notes |+|------|--------|-------|+| `src/managed/Nota.App/MainWindow.DetailWindow.cs` | modified | `SetHost`: when the source and target hosts are in different top-levels, detach, then `from.UpdateLayout()`, then attach |+| `src/managed/Nota.App/DetailWindow.cs` | modified | `OnClosing`: detach both hosts, then `UpdateLayout()`, before `DockRequested` re-hosts them in the main window |+| `CHANGELOG.md` | modified | `[Unreleased] → Fixed` entry |++## Diff Highlights++```csharp+if (content?.Parent is ContentControl prev && !ReferenceEquals(prev, host))+{+ var from = TopLevel.GetTopLevel(prev);+ prev.Content = null;+ if (from is not null && !ReferenceEquals(from, TopLevel.GetTopLevel(host))) from.UpdateLayout();+}+```++## Tests Added or Updated++No automated test in the repo. The smoke test doesn't reference Nota.App or Avalonia.Headless, and adding+a headless UI test project would be a new dependency the assessment didn't settle. The checks below ran+in a throwaway harness, `/tmp/crosswinharness`: a console project with a ProjectReference to Nota.App plus+Avalonia.Headless and Avalonia.Skia 12.0.3. Run it with `NOTA_DATA_DIR=/tmp/crosswinharness/data dotnet run`.++- **Generic case:** a control is queued for layout in window A, moved into window B, then B is resized and+ re-measured after `Show` (like X11's ConfigureNotify / scale event), then A's layout pass runs.+ - Raw move: `ArgumentException: Attempt to call InvalidateArrange on wrong LayoutManager.` This is the+ exact exception from the tester's log.+ - Through the real `MainWindow.SetHost` (reflected): before the fix it throws the same; after the fix, ok.+- **Real app:** a headless `MainWindow` with a MIDI clip open in the docked piano roll. Queue live+ updates, call `OnToggleDetailWindow`, then dump the main window's layout queue.+ - Before the fix: dozens of entries (ContentPresenter, Grid, ClipPropsView, …) that belong to+ `DetailWindow`. This is the stale state that crashes on X11.+ - After the fix: only the main window's own `Grid` (the collapsed detail row).+ - Pop-out and re-dock both run without exceptions.++## Local Verification++- `scripts/build.sh` (macOS arm64) → exit 0, `SMOKE TEST PASSED`.+- Headless harness as above → `ALL PASS` with the fix; `1 FAIL` (the exact exception) without it.+- Not run on Linux. The tester on Fedora (X11) should confirm, see `/speckit-bug-test`.++## Deviations from Assessment++- **Order of the flush.** The assessment proposed `UpdateLayout()` *before* the detach. The harness showed that+ the detach itself (`prev.Content = null`) queues the moved control and its children in the old window's+ layout manager again. So the flush runs *after* the detach and before the attach, in both `SetHost` and+ `DetailWindow.OnClosing`.+- **Mixer left alone.** The assessment expected the mixer pop-out to crash too. `_mixer` is created+ without a parent in the main window (`MainWindow.axaml.cs:387`), so nothing of it can be queued there when+ it moves to `MixerWindow`. `MainWindow.Mixer.cs` and `MixerWindow.cs` are unchanged.+- **No headless test in the repo** (see above).++## Follow-ups++- Ask the Fedora tester to try the build: pop out, close, pop out again, during playback.+- Optional safety net: `Dispatcher.UIThread.UnhandledException` → log, so a UI-only exception doesn't+ kill the session. This needs a separate decision, because it can hide broken state.+- A headless UI test project would let checks like this live in CI. Decide on the dependency first.diff --git a/.specify/bugs/linux-detail-window-crash/test.md b/.specify/bugs/linux-detail-window-crash/test.mdnew file mode 100644index 00000000..43ade71f--- /dev/null+++ b/.specify/bugs/linux-detail-window-crash/test.md@@ -0,0 +1,50 @@+# Bug Verification: Linux — app aborts when the piano roll is popped out into its own window++- **Slug**: linux-detail-window-crash+- **Tested**: 2026-10-15+- **Assessment**: ./assessment.md+- **Fix**: ./fix.md+- **Result**: verified++## Summary++The original reporter's setup (Fedora, X11 back end, AppImage) no longer crashes when the piano roll is+popped out, with a build that contains only this fix on top of `develop`. The headless repro fails with the+exact exception without the fix and passes with it. The full build and smoke test pass.++## Checks Performed++| Check | Command / Action | Result | Notes |+|-------|------------------|--------|-------|+| Reproduction (post-fix), real environment | Tester on Fedora ran `Nota-0.53.1-detailfix-x86_64.AppImage` (sha256 `d2c46a0a…f4f87`, built from `develop` HEAD `3d38e2f` + the fix only) and popped out Devices / Clip | pass | Reported by the user: "Все ок, работает". The same action crashed 0.53.x before. |+| Headless repro, generic | `/tmp/crosswinharness`: `NOTA_DATA_DIR=/tmp/crosswinharness/data dotnet run` | pass | Raw cross-window move throws `InvalidateArrange on wrong LayoutManager`; the real `MainWindow.SetHost` doesn't |+| Headless repro, real MainWindow | same harness, `AppCase` | pass | After pop-out, the main window's layout queue holds only its own `Grid` (before the fix it held dozens of DetailWindow controls); pop-out and re-dock run without exceptions |+| Regression suite | `scripts/build.sh` (macOS arm64) | pass | Run during `/speckit-bug-fix`, on the same source as now (no changes since): exit 0, `SMOKE TEST PASSED` |+| Linux x64 build | `scripts/package-linux.sh` in `mcr.microsoft.com/dotnet/sdk:10.0` (linux/amd64) | pass | Native engine + self-contained publish + AppImage |+| Lint / type-check | — | not-run | No separate linter; the C# compile in the build/harness is the type-check |++## Output Excerpts++```+B shown=True resized=True: raw move → ArgumentException: Attempt to call InvalidateArrange on wrong LayoutManager. | SetHost → ok+app: main queue after pop-out: m[Grid] a[]+PASS app: pop out+PASS app: re-dock (clip editor in nothing)+ALL PASS+```++## Residual Risks++- The Fedora check is a report relayed by the user (one machine, X11). Wayland-native and other desktops+ were not tried. Avalonia 12 runs through XWayland there, so this is the same back end.+- No automated test in the repo. The harness lives in `/tmp` and isn't in CI, so a regression in `SetHost`+ would only show up on Linux by hand.+- Windows and macOS were not re-checked by hand. The change only adds a layout flush when a control moves+ between windows. The smoke test passes.++## Recommendation++Close the bug — verified end-to-end on the reporter's Linux setup plus headless repro. Commit the two source+files and the CHANGELOG entry. Keep the `CHANGELOG.md` hunk separate from the unrelated Linux settings-folder+entry that's also uncommitted there. A headless UI test project for checks like this is a separate decision+(new dependency).diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 97560c3b..3860e8b4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -95,6 +95,10 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.chain.### Fixed+- **Popping out the piano roll no longer crashes on Linux:** opening Devices / Clip in its+ own window could close Nota at once on Linux ("Attempt to call InvalidateArrange on wrong+ LayoutManager"). The editor's pending layout in the main window is now finished before it+ moves to the new window, and the same on the way back.- **The transport meter says what it measures:** it read "CPU" but showed only the audioengine's load, so it sat far below the system monitor. It is now labelled **DSP** — theshare of each audio buffer the engine needs, which is what causes dropouts — and itsdiff --git a/src/managed/Nota.App/DetailWindow.cs b/src/managed/Nota.App/DetailWindow.csindex 267022f6..12d109fc 100644--- a/src/managed/Nota.App/DetailWindow.cs+++ b/src/managed/Nota.App/DetailWindow.cs@@ -78,9 +78,11 @@ internal sealed class DetailWindow : NotaWindowbase.OnClosing(e);if (e.Cancel) return;// Detach the hosted controls before they go back to the main window (a control- // can have only one parent).+ // can have only one parent), then run this window's pending layout so no entry+ // queued for them here outlives the move (see MainWindow.SetHost).ClipHost.Content = null;ChainHost.Content = null;+ UpdateLayout();DockRequested?.Invoke();}}diff --git a/src/managed/Nota.App/MainWindow.DetailWindow.cs b/src/managed/Nota.App/MainWindow.DetailWindow.csindex f17da8df..99ad876e 100644--- a/src/managed/Nota.App/MainWindow.DetailWindow.cs+++ b/src/managed/Nota.App/MainWindow.DetailWindow.cs@@ -28,10 +28,19 @@ public partial class MainWindowprivate ContentControl ClipDetailHost => _detailWindow?.ClipHost ?? DetailBody;// Assign a control to a ContentControl host, detaching it from any previous host first- // (a control can have only one parent).+ // (a control can have only one parent). Moving to another window, the old window's+ // pending layout is run between the detach and the attach: each window keeps its own+ // layout queue (the detach itself queues the control there), and an entry left behind for+ // a control that now lives in the other window throws "InvalidateArrange on wrong+ // LayoutManager" on a later frame (seen on Linux/X11 popping out the piano roll).private static void SetHost(ContentControl host, Control? content){- if (content?.Parent is ContentControl prev && !ReferenceEquals(prev, host)) prev.Content = null;+ if (content?.Parent is ContentControl prev && !ReferenceEquals(prev, host))+ {+ var from = TopLevel.GetTopLevel(prev);+ prev.Content = null;+ if (from is not null && !ReferenceEquals(from, TopLevel.GetTopLevel(host))) from.UpdateLayout();+ }if (!ReferenceEquals(host.Content, content)) host.Content = content;}