fix: crash when cancelling the session manager on macOS (#2433) - #2547
Conversation
|
Also looks ok to me. Only one thing: please prefer the existing HeidiSQL/source/apphelpers.pas Line 3781 in 8644cd7 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
0a26ca0 to
715a5b3
Compare
|
Done, pulled your latest changes and rebased, so the PR now only contains the remaining pieces: the Unlike 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. |
Two independent crashes on macOS were hidden behind this repro, since cancelling the session manager at startup also exits the application:
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.
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