Fix hang and wrong check states in data grid column selection on macOS - #2559
Merged
ansgarbecker merged 1 commit intoJul 23, 2026
Merged
Conversation
Fixes the reported hang (issue 2554): closing the column selection popup with OK could run FormClose twice on macOS, freeing FCheckedColumns two times. The resulting access violation raised the crash dialog inside a paint cycle, freezing the application. FCheckedColumns is now freed in FormDestroy, which runs exactly once. While verifying that fix, a second bug in the same popup showed up: checked columns were not applied correctly to the grid. The click handler used ItemIndex to detect the toggled item, but on Cocoa the check event fires before the list selection is updated, so the wrong item was added or removed. The handler now syncs the check states of all displayed items instead.
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 #2554
Debugged with lldb on an M-series Mac. There were two separate bugs in the column selection popup, both fixed here:
1. The reported hang (double-free of FCheckedColumns)
Clicking OK closes the popup, which frees
FCheckedColumnsinFormClose. But the form itself is only released deferred (caFree), and the grid reload triggered by OK makes the main window key again while the popup object still exists. The LCL then sendsCM_DEACTIVATEto the popup →FormDeactivate→btnCancelClick→Closeruns a second time →FCheckedColumns.Freeon the already freed list. The resulting access violation raises the crash dialog withShowModalinside the data grid's paint cycle, where nothing can be drawn anymore - the app freezes with an invisible modal dialog.Backtrace of the crash (captured with lldb, trimmed):
frame #1: SYSTEM$$TOBJECT$$$FREE
frame #2: TFRMCOLUMNSELECTION$$$FORMCLOSE ← 2nd time
frame #5: TFRMCOLUMNSELECTION$$$BTNCANCELCLICK
frame #6: TFRMCOLUMNSELECTION$$$FORMDEACTIVATE
frame #14: TSCREEN$$$SETFOCUSEDFORM
frame #23: -[TCocoaWindow windowDidBecomeKey:]
frame #31: -[NSWindow makeKeyWindow]
frame #38: APPHELPERS$$$TRYSETFOCUS
frame #39: TMAINFORM$__$$_DATAGRIDBEFOREPAINT ← grid reload after OK
Fix: free
FCheckedColumnsinFormDestroy, which runs exactly once.TApplication.ReleaseComponentalready tolerates the duplicateRelease, so the second close pass is harmless otherwise.2. Checked columns were applied wrongly (stale ItemIndex)
After fixing the hang, selecting e.g. 3 columns still showed only 1 in the grid.
chklistColumnsClickCheckusedchklistColumns.ItemIndexto detect the toggled item. On Cocoa the checkbox is anNSButtoninside the table row, and its action fires before the table selection is updated - soItemIndexstill points at the previously clicked row, or is -1. Verified with lldb: clicking checkboxes of rows 0, 2, 1 deliveredLM_CHANGEDfor rows 0, 2, 1 whileselectedRowwas -1, 0, 4 at those moments - the internal list diverged from the visible check marks on every click.Fix: sync the check states of all currently displayed items into
FCheckedColumnsinstead of guessing viaItemIndex. Items hidden by the filter box are not touched, so filtering still works, and behavior on Windows is unchanged (no ifdefs).Tested on macOS 15 (Apple Silicon): the reported hang scenario, multiple checkbox clicks without/with row selection changes in between, select/deselect all, sorting and filtering.