Skip to content

Commit 3ebc530

Browse files
LSalamiclaude
andcommitted
fix(gui): guard invalid dataview item and fix sidebar label measurement
EVT_DATAVIEW_SELECTION_CHANGED also fires when the selection is cleared, unlike the old EVT_LIST_ITEM_SELECTED, and GetItemData() on an invalid item crashes outright. Also measure the sidebar label width with m_PrefsIcons's own font instead of the dialog's, since the two can differ on native backends. Addresses review feedback from got3nks on #671. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent bbdf83c commit 3ebc530

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/PrefsUnifiedDlg.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ PrefsUnifiedDlg::PrefsUnifiedDlg(wxWindow *parent)
406406
}
407407

408408
const wxString label = wxGetTranslation(pages[i].m_title);
409-
maxLabelWidth = std::max(maxLabelWidth, GetTextExtent(label).GetWidth());
409+
maxLabelWidth = std::max(maxLabelWidth, m_PrefsIcons->GetTextExtent(label).GetWidth());
410410

411411
// Add each page to the page-list. Item data is this page's stable
412412
// pages[] index (never reordered -- only which pages are visible
@@ -2332,6 +2332,15 @@ void PrefsUnifiedDlg::UpdateGeoIPStatus()
23322332

23332333
void PrefsUnifiedDlg::OnPrefsPageChange(wxDataViewEvent &event)
23342334
{
2335+
// EVT_DATAVIEW_SELECTION_CHANGED, unlike the old EVT_LIST_ITEM_SELECTED,
2336+
// also fires when the selection is cleared, in which case GetItem() is
2337+
// not valid and GetItemData() on it would crash outright. Nothing here
2338+
// currently clears the sidebar's selection, so this is a guard against
2339+
// future changes rather than a fix for a live bug.
2340+
if (!event.GetItem().IsOk()) {
2341+
return;
2342+
}
2343+
23352344
prefs_sizer->Detach(m_CurrentPanel);
23362345
m_CurrentPanel->Show(false);
23372346

0 commit comments

Comments
 (0)