Compare commits

...
1 Commits
Author SHA1 Message Date
noahandClaude Opus 4.8 50cd463bee 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
2026-09-18 10:29:14 -06:00
2 changed files with 15 additions and 5 deletions
+8 -3
View File
@@ -1,6 +1,6 @@
--- a/cpp_src/widgets_bridge.cpp --- a/cpp_src/widgets_bridge.cpp
+++ b/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 +// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
+// Adds the widget/event surface the toolkit UI needs on top of the upstream +// Adds the widget/event surface the toolkit UI needs on top of the upstream
+// render-callback bridge (which is kept untouched). +// 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 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) { +void wxbr_dvlc_ensure_visible(void* win, unsigned row) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ if (row >= (unsigned)dvlc_store(win)->GetItemCount()) return;
+ wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row); + wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row);
+ if (item.IsOk()) dv->EnsureVisible(item); + if (item.IsOk()) dv->EnsureVisible(item);
+} +}
@@ -806,9 +808,11 @@
+void wxbr_dvlc_select_rows(void* win, const int* rows, int n) { +void wxbr_dvlc_select_rows(void* win, const int* rows, int n) {
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); + wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
+ int count = (int)dvlc_store(win)->GetItemCount();
+ dv->UnselectAll(); + dv->UnselectAll();
+ for (int i = 0; i < n; i++) { + 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; + if (row < 0) return;
+ wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
+ wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); + wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
+ if (row >= (long)dvlc_store(win)->GetItemCount()) return;
+ dv->Select(m->GetItem((unsigned)row)); + dv->Select(m->GetItem((unsigned)row));
+} +}
+ +
@@ -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 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) { void wxbr_dvlc_ensure_visible(void* win, unsigned row) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)win; wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
if (row >= (unsigned)dvlc_store(win)->GetItemCount()) return;
wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row); wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row);
if (item.IsOk()) dv->EnsureVisible(item); 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) { void wxbr_dvlc_select_rows(void* win, const int* rows, int n) {
wxDataViewCtrl* dv = (wxDataViewCtrl*)win; wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
int count = (int)dvlc_store(win)->GetItemCount();
dv->UnselectAll(); dv->UnselectAll();
for (int i = 0; i < n; i++) { 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; if (row < 0) return;
wxDataViewCtrl* dv = (wxDataViewCtrl*)win; wxDataViewCtrl* dv = (wxDataViewCtrl*)win;
wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel();
if (row >= (long)dvlc_store(win)->GetItemCount()) return;
dv->Select(m->GetItem((unsigned)row)); dv->Select(m->GetItem((unsigned)row));
} }