Skip to content

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

Open
twinn1013 wants to merge 1 commit into
HeidiSQL:lazarusfrom
twinn1013:fix-session-manager-cancel-crash
Open

fix: crash when cancelling the session manager on macOS (#2433)#2547
twinn1013 wants to merge 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

…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 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.

Fixes issue 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?

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