summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-06-25 00:05:50 +0200
committerCarl Hetherington <cth@carlh.net>2024-06-25 00:06:16 +0200
commitce087143165a0306b8c51eccaf08bfdd118d0e92 (patch)
treef08581f25dece5e784f169aaea8359f1749553e6
parentb11083f68b7971556e5003093b44c1835407b315 (diff)
Fix assertion failure after removing content.
Adding, say, 10 items of content, removing the last 8 and then clicking somewhere in the content list would cause OnGetItem{Text,Attr} to be called with a high index (as if the items had not yet been removed).
-rw-r--r--src/wx/content_panel.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc
index 07a632b4a..5624e8797 100644
--- a/src/wx/content_panel.cc
+++ b/src/wx/content_panel.cc
@@ -211,26 +211,35 @@ public:
wxString OnGetItemText(long item, long) const override
{
- DCPOMATIC_ASSERT(item >= 0 && item < static_cast<long>(_items.size()));
+ if (out_of_range(item)) {
+ /* wxWidgets sometimes asks for things that are already gone */
+ return {};
+ }
wxClientDC dc(const_cast<wxWindow*>(static_cast<wxWindow const*>(this)));
return wxControl::Ellipsize(_items[item].text, dc, wxELLIPSIZE_MIDDLE, GetSize().GetWidth());
}
wxListItemAttr* OnGetItemAttr(long item) const override
{
- DCPOMATIC_ASSERT(item >= 0 && item < static_cast<long>(_items.size()));
+ if (out_of_range(item)) {
+ return nullptr;
+ }
return _items[item].error ? const_cast<wxListItemAttr*>(&_red) : nullptr;
}
weak_ptr<Content> content_at_index(long index)
{
- if (index < 0 || index >= static_cast<long>(_items.size())) {
+ if (out_of_range(index)) {
return {};
}
return _items[index].content;
}
private:
+ bool out_of_range(long index) const {
+ return index < 0 || index >= static_cast<long>(_items.size());
+ }
+
std::vector<Item> _items;
wxListItemAttr _red;
};