Skip to content

fix: crash when cancelling the session manager on macOS (#2433) - #2547

Merged
ansgarbecker merged 1 commit into
HeidiSQL:lazarusfrom
twinn1013:fix-session-manager-cancel-crash
Jul 17, 2026
Merged

fix: crash when cancelling the session manager on macOS (#2433)#2547
ansgarbecker merged 1 commit into
HeidiSQL:lazarusfrom
twinn1013:fix-session-manager-cancel-crash

Conversation

@twinn1013

Copy link
Copy Markdown
Collaborator

Two independent crashes on macOS were hidden behind this repro, since cancelling the session manager at startup also exits the application:

  1. The session manager starts an inline rename right after creating a new session. When the form was closed via Cancel, the edit link's queued async EndEditNode call fired after the tree was already destroyed, and its focus restoration ran into "[TCustomForm.SetFocus] connform:Tconnform Can not focus". Remove pending async edit calls when an editor link is destroyed, cancel a pending inline rename before the form closes, and add a SetFocusSafe() helper based on CanSetFocus, which - unlike CanFocus - also checks the parent form itself.

  2. On shutdown, TSynBaseCompletionForm.Destroy (SynEdit) first frees its SizeDrag panel and then destroys the window handle. The Cocoa widgetset queries Focused during DestroyHandle, and SynEdit's Focused override dereferences the freed SizeDrag, raising "EObjectCheck: Object reference is Nil" on every macOS shutdown. Work around it by destroying the completion form's handle in FormDestroy while the form is still intact.

Verified on an M5 MacBook Pro (macOS 26) under lldb with breakpoints on FPC_RAISEEXCEPTION / FPC_CHECK_OBJECT: before the fix both exceptions fired; after the fix the app exits cleanly with status 0.

Fixes #2433

@twinn1013 twinn1013 self-assigned this Jul 14, 2026
@twinn1013 twinn1013 added the macos Affects the macOS app bundle label Jul 14, 2026
@twinn1013
twinn1013 requested a review from ansgarbecker July 14, 2026 05:25
@twinn1013 twinn1013 added the bug Defective behaviour in HeidiSQL label Jul 14, 2026
@twinn1013
twinn1013 removed the request for review from ansgarbecker July 14, 2026 08:30
@ansgarbecker

Copy link
Copy Markdown
Collaborator

Also looks ok to me. Only one thing: please prefer the existing TrySetFocus from

procedure TWinControlHelper.TrySetFocus;

Maybe through catching exceptions in TrySetFocus the TWinControlAccess quirk is not even required?

…active

Two independent crashes on macOS were hidden behind this repro, since
cancelling the session manager at startup also exits the application:

1. The session manager starts an inline rename right after creating a
   new session. When the form was closed via Cancel, the edit link's
   queued async EndEditNode call fired after the tree was already
   destroyed, and its focus restoration ran into
   "[TCustomForm.SetFocus] connform:Tconnform Can not focus".
   Remove pending async edit calls when an editor link is destroyed,
   cancel a pending inline rename before the form closes, and let
   TrySetFocus test CanSetFocus, which - unlike CanFocus - also checks
   the parent form itself, so it does not raise in the first place.

2. On shutdown, TSynBaseCompletionForm.Destroy (SynEdit) first frees its
   SizeDrag panel and then destroys the window handle. The Cocoa
   widgetset queries Focused during DestroyHandle, and SynEdit's Focused
   override dereferences the freed SizeDrag, raising
   "EObjectCheck: Object reference is Nil" on every macOS shutdown.
   Work around it by destroying the completion form's handle in
   FormDestroy while the form is still intact.

Fixes issue 2433
@twinn1013
twinn1013 force-pushed the fix-session-manager-cancel-crash branch from 0a26ca0 to 715a5b3 Compare July 17, 2026 13:59
@twinn1013

Copy link
Copy Markdown
Collaborator Author

Done, pulled your latest changes and rebased, so the PR now only contains the remaining pieces: the CanSetFocus change in TrySetFocus, plus the three fixes from the original PR (dropping queued async edit calls, cancelling a pending inline rename on close, and the Darwin-only SynEdit completion form workaround).

Unlike CanFocus, CanSetFocus also tests the parent form itself exactly the case that raised [TCustomForm.SetFocus] ... Can not focus here. Attempts that cannot succeed are now skipped cleanly instead of raising; your exception handler stays as a last resort.

About the TWinControlAccess quirk: exception catching can't replace it, because that crash happens inside TSynBaseCompletionForm's own destructor chain (Cocoa DestroyHandle → Focused → already-freed SizeDrag), not at any focus call site we control. Destroying the handle early in FormDestroy is the only intervention point I found backtrace is in the PR description.

@ansgarbecker
ansgarbecker merged commit 1da8683 into HeidiSQL:lazarus Jul 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Defective behaviour in HeidiSQL macos Affects the macOS app bundle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants