mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
C++: Fix segfault when calling Model::row_changed() after Model::reset()
Fixes #8021
This commit is contained in:
parent
bd093b5119
commit
4145eafe14
2 changed files with 47 additions and 0 deletions
|
@ -852,6 +852,10 @@ class Repeater
|
|||
|
||||
void row_added(size_t index, size_t count) override
|
||||
{
|
||||
if (index > data.size()) {
|
||||
// Can happen before ensure_updated was called
|
||||
return;
|
||||
}
|
||||
is_dirty.set(true);
|
||||
data.resize(data.size() + count);
|
||||
std::rotate(data.begin() + index, data.end() - count, data.end());
|
||||
|
@ -862,6 +866,9 @@ class Repeater
|
|||
}
|
||||
void row_changed(size_t index) override
|
||||
{
|
||||
if (index >= data.size()) {
|
||||
return;
|
||||
}
|
||||
auto &c = data[index];
|
||||
if (model && c.ptr) {
|
||||
(*c.ptr)->update_data(index, *model->row_data(index));
|
||||
|
@ -872,6 +879,10 @@ class Repeater
|
|||
}
|
||||
void row_removed(size_t index, size_t count) override
|
||||
{
|
||||
if (index + count > data.size()) {
|
||||
// Can happen before ensure_updated was called
|
||||
return;
|
||||
}
|
||||
is_dirty.set(true);
|
||||
data.erase(data.begin() + index, data.begin() + index + count);
|
||||
for (std::size_t i = index; i < data.size(); ++i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue