Skip to content

Keep a closed panel's callbacks alive until its frame is drawn - #333

Merged
LogicalError merged 1 commit into
mainfrom
tachyonui/close-panel-after-frame
Nov 21, 2026
Merged

LogicalError merged 1 commit into
mainfrom
tachyonui/close-panel-after-frame

Conversation

@LogicalError

Copy link
Copy Markdown
Owner

Closing a docked panel with Ctrl+W, Ctrl+F4 or its tab menu's Close could make the frame read freed memory.

Cause

  • Those three run while input is handled: after the frame is built, before it's drawn.
  • ClosePanel destroyed the Panel there, and with it what its callbacks held. In the showcase, that's the panel's own state.
  • A Viewport built earlier that frame had already queued its scene with a pointer into that state (controls_viewport.cpp, RenderScene). When the frame was drawn, the scene callback read freed memory.
  • A custom draw that captures a view's state is open to the same thing.

What changes

  • ClosePanel waits to destroy: ClosePanel, and closing all of a layout's panels, still take the panels out of the layout at once and give their IDs back. The Panel objects are now kept until the next frame starts (BeginDockingFrame), or until Cleanup.
  • Safe from an input handler: a panel can now be closed from one, such as a button in it.
  • Docs: the docking guide says so, and the changelog has an entry.

Tests

  • New: a panel closed by a click on a button in it is out of the layout at once, and its ID is back. What its callback holds lives through that frame and goes when the next frame starts. Before the fix, that last check failed.

Validation

  • Full Debug build: no errors or warnings.
  • gui_core_tests, gui_vulkan_tests, gui_gpu_tests, gui_d3d12_tests and gui_sdlgpu_tests all pass on Windows.
  • A showcase --bench run reports no errors.

Ctrl+W, Ctrl+F4 and a tab menu's Close close a docked panel while input
is handled, after the frame is built and before it's drawn. ClosePanel
destroyed the panel there, and with it what its callbacks held. A
viewport built that frame had already queued its scene with a pointer
into that state, and the scene read freed memory when it was drawn.

- ClosePanel and closing a layout's panels take them out of the layout at
  once and give their IDs back, but keep the Panel objects until the next
  frame starts (BeginDockingFrame), or until Cleanup.
- Docs: closing a panel from an input handler.
- Tests: a panel closed by a click on a button in it is out of the layout
  and its ID is back at once, while what its callback holds lives until
  the next frame starts.
@LogicalError
LogicalError merged commit a2f1a7d into main Nov 21, 2026
8 checks passed
@LogicalError
LogicalError deleted the tachyonui/close-panel-after-frame branch November 21, 2026 21:07
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