From 50cd463bee17dcd83e9b0d0844bf04ea6cc1db11 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 18 Sep 2026 10:29:14 -0600 Subject: [PATCH] GUI fix: guard out-of-range dvlc GetItem (crash selecting rows after refresh) Round-9 #10: selecting miners could trip `datavcmn.cpp: assert "row < m_hash.GetCount()" failed in GetItem(): invalid index` and crash. wxDataViewIndexListModel::GetItem() asserts on an out-of-range row, and three bridge helpers called it with an index that can go stale when the row set shrinks (a filter, or a scan that returns fewer rows): wxbr_dvlc_ ensure_visible (the round-8 scroll-hold, unguarded), wxbr_dvlc_select_rows and wxbr_dvlc_select_row (only lower-bounded). All three now bound the row against the store's item count before calling GetItem, so a stale/empty index is a no-op instead of a crash. Local wx-rs bridge compile clean; patch 0003 regenerated + validated. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh --- thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch | 11 ++++++++--- .../wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index d62ea92e..b5ffac76 100644 --- a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch +++ b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch @@ -1,6 +1,6 @@ --- a/cpp_src/widgets_bridge.cpp +++ b/cpp_src/widgets_bridge.cpp -@@ -0,0 +1,1059 @@ +@@ -0,0 +1,1064 @@ +// widgets_bridge.cpp — alkane-toolkit extension to wx-rs +// Adds the widget/event surface the toolkit UI needs on top of the upstream +// render-callback bridge (which is kept untouched). @@ -701,9 +701,11 @@ +} + +// Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the -+// scroll position after a refill). Out-of-range rows are ignored. ++// scroll position after a refill). Out-of-range rows are ignored -- GetItem() ++// itself asserts on row >= count, so the bound MUST be checked before calling. +void wxbr_dvlc_ensure_visible(void* win, unsigned row) { + wxDataViewCtrl* dv = (wxDataViewCtrl*)win; ++ if (row >= (unsigned)dvlc_store(win)->GetItemCount()) return; + wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row); + if (item.IsOk()) dv->EnsureVisible(item); +} @@ -806,9 +808,11 @@ +void wxbr_dvlc_select_rows(void* win, const int* rows, int n) { + wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); ++ int count = (int)dvlc_store(win)->GetItemCount(); + dv->UnselectAll(); + for (int i = 0; i < n; i++) { -+ if (rows[i] >= 0) dv->Select(m->GetItem((unsigned)rows[i])); ++ // GetItem() asserts on an out-of-range row, so bound both ends. ++ if (rows[i] >= 0 && rows[i] < count) dv->Select(m->GetItem((unsigned)rows[i])); + } +} + @@ -827,6 +831,7 @@ + if (row < 0) return; + wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); ++ if (row >= (long)dvlc_store(win)->GetItemCount()) return; + dv->Select(m->GetItem((unsigned)row)); +} + diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp index 4f11c301..8fdbd578 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp @@ -698,9 +698,11 @@ int wxbr_dvlc_get_top_row(void* win) { } // Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the -// scroll position after a refill). Out-of-range rows are ignored. +// scroll position after a refill). Out-of-range rows are ignored -- GetItem() +// itself asserts on row >= count, so the bound MUST be checked before calling. void wxbr_dvlc_ensure_visible(void* win, unsigned row) { wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + if (row >= (unsigned)dvlc_store(win)->GetItemCount()) return; wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row); if (item.IsOk()) dv->EnsureVisible(item); } @@ -803,9 +805,11 @@ int wxbr_dvlc_get_selections(void* win, int* buf, int cap) { void wxbr_dvlc_select_rows(void* win, const int* rows, int n) { wxDataViewCtrl* dv = (wxDataViewCtrl*)win; wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); + int count = (int)dvlc_store(win)->GetItemCount(); dv->UnselectAll(); for (int i = 0; i < n; i++) { - if (rows[i] >= 0) dv->Select(m->GetItem((unsigned)rows[i])); + // GetItem() asserts on an out-of-range row, so bound both ends. + if (rows[i] >= 0 && rows[i] < count) dv->Select(m->GetItem((unsigned)rows[i])); } } @@ -824,6 +828,7 @@ void wxbr_dvlc_select_row(void* win, long row) { if (row < 0) return; wxDataViewCtrl* dv = (wxDataViewCtrl*)win; wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); + if (row >= (long)dvlc_store(win)->GetItemCount()) return; dv->Select(m->GetItem((unsigned)row)); }