Clear the window on teardown so Start can run again - #422
Merged
Merged
Conversation
Start()'s teardown disposed the window but left the static field set, so the guard at the top of Start() reported "Application is already running." for the rest of the process even though nothing was. Reset() clears the field but is internal to the test assembly, so consumers had no way out: restart-to-apply-settings, and any harness driving sequential sessions, were impossible. EmbeddedSession.RunLoop's finally block already cleared the field, so the two paths had drifted. Rather than copy the clears into Start(), both now end in a single TeardownWindow() that disposes the controller, the input context and the GL context before disposing the window and clearing it. The cleanups are idempotent, so running after the window's Closing handler has already done them is a no-op. Fixes #404 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZcLBdphhSBSNeUALeVhxB
|
This was referenced Sep 17, 2026
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.



Fixes #404
What was wrong
Start()'s teardown disposed the window but never cleared the staticwindowfield. The guard at the top ofStart()reads that field, so every later call threwInvalidOperationException("Application is already running.")for the rest of the process — with nothing actually running.Reset()clears the field, but it isinternaland visible only to the test assembly, so consumers had no workaround. Restart-to-apply-settings, and any harness driving sequential sessions in one process, were impossible.EmbeddedSession.RunLoop'sfinallyblock already cleared the field, with a comment saying it does so by design, so the two lifecycle paths had drifted.The change
Both paths now end in one
TeardownWindow(), rather than each carrying its own list of fields to clear:Cleanup*helpers, all of which are idempotent — the window'sClosinghandler has usually run them already), then disposes the window and clears itStart()'s blocking branch is factored intoRunWindowLoop(), which runs the loop and then tears down; this also makes the post-loop path reachable from a test without a real windowEmbeddedSession.RunLoop'sfinallycalls the same helper, so its teardown now also releases the GL resources on an abnormal exitThe embedded path gains GL/controller/input cleanup it did not have; nothing else changes behaviour.
Tests
New
tests/ImGui.App.Tests/WindowTeardownTests.cs:RunWindowLoopDisposesTheWindowAndClearsIt— the window is disposed and the field is null once the loop returnsRunWindowLoopReleasesTheResourcesThatHungOffTheWindow— the input context is disposed, andcontroller,renderer,glandglProviderare clearedStartIsAllowedAgainOnceTheRunLoopHasReturned— the issue's acceptance criterion:Start→ loop returns →Startagain succeedsAll three fail against the old teardown (the third with the exact
Application is already running.from the issue) and pass with the fix. FullImGui.App.Testssuite: 431/431 passing on this branch.🤖 Generated with Claude Code
https://claude.ai/code/session_01AZcLBdphhSBSNeUALeVhxB
Generated by Claude Code