Repository navigation
Fix crash and stalled Windows shutdown when MyFrame::OnClose runs twice - #1475
Draft
riggsbrown wants to merge 1 commit into
Draft
riggsbrown wants to merge 1 commit into
riggsbrown wants to merge 1 commit into
Conversation
On Windows, wxApp::OnQueryEndSession calls Close() on the top window for
every WM_QUERYENDSESSION, and Windows sends that message to each of the
application's top-level windows (the main frame, the Advanced Settings and
Connect Equipment dialogs, ...). MyFrame::OnClose therefore runs more than
once during a logoff or restart. The second call dereferences the help
controller that the first call deleted and set to null
(help->GetFrame()), an access violation at a fixed offset in phd2.exe.
Observed on 2.6.14 (32-bit) under Windows 11: the crash during the
restart's query phase leaves phd2.exe running, Windows abandons the restart
("failed to terminate the currently logged on user's processes") and the
user is returned to the lock screen with the rest of their session already
closed. For unattended remote observatories that is a night lost.
Make OnClose idempotent: remember that the shutdown has run and return
early on later calls, and null-check help before using it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #1474
MyFrame::OnClosedeletes the help controller and setshelpto null. A second call thencrashes at
help->GetFrame(). On Windows that second call is routine:WM_QUERYENDSESSIONtowxApp::OnQueryEndSession,which calls
Close()on the top window. Windows sends the message to each top-level window, andPHD2 has several (main frame, hidden
wxWindowNR, Advanced Settings, Connect Equipment). Thecrash leaves
phd2.exerunning and Windows abandons the restart. On an unattended observatorythat leaves the PC sitting at the lock screen with nothing running.
visible TLW in
Destroy()).On one rig this is 34 crashes at
phd2.exe+0x1D3EB3in 2.6.14 since June, and 5 abandoned Windowsrestarts. Details, disassembly and logs are in the issue.
Change
m_closed, set onceOnClosepasses the veto check. Later calls logMyFrame::OnClose already closedand return without vetoing, so the close or end-session goesahead, and
Destroy()from the first call is already pending.helpbefore using it.The veto path is unchanged: if the user cancels the "exit while capturing" prompt,
m_closedstaysfalse and a later close runs the full shutdown.
Testing
repro_double_close.py --sendagainst PHD2 + simulator: oneOnClose proceeding, thenOnClose already closedfor each later message, andphd2.exeexits with no crashI could not build this locally (no MSVC toolchain on the machine where it was found). The boxes
above are the plan, not results.
🤖 Generated with Claude Code