forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panic when trying to access layout cache of destroyed items
This can be reproduced by deleting the last item of the printer queue in the printer demo. It is a regression showing up because we now emit the MouseExit event after the mouse grab as released. The problem is that we upgrade the weak item, and call geometry() on it. Calling geometry will re-evaluate the layout cache which will re-evaluate the model which will result in the component being removed and the cache entry having less item than expected. It is ok to simply return 0. for these layout location since the item will disapear anyway.
- Loading branch information
Showing
5 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* LICENSE BEGIN | ||
This file is part of the SixtyFPS Project -- https://sixtyfps.io | ||
Copyright (c) 2021 Olivier Goffart <olivier.goffart@sixtyfps.io> | ||
Copyright (c) 2021 Simon Hausmann <simon.hausmann@sixtyfps.io> | ||
|
||
SPDX-License-Identifier: GPL-3.0-only | ||
This file is also available under commercial licensing terms. | ||
Please contact info@sixtyfps.io for more information. | ||
LICENSE END */ | ||
|
||
// issue #177 | ||
|
||
export TestCase := Window { | ||
width: 100px; | ||
height: 100px; | ||
|
||
callback clicked; | ||
clicked => { debug("Hello"); model= []; } | ||
property <bool> hover <=> under.has-hover; | ||
property<[int]> model: [1]; | ||
VerticalLayout { | ||
under := TouchArea { | ||
HorizontalLayout { | ||
for value in model: TouchArea { | ||
horizontal-stretch: 5; | ||
vertical-stretch: 5; | ||
clicked => { root.clicked(); } | ||
Rectangle { background: blue; } | ||
} | ||
} | ||
} | ||
Rectangle { | ||
horizontal-stretch: 0; | ||
vertical-stretch: 0; | ||
background: yellow; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
/* | ||
|
||
```cpp | ||
auto handle = TestCase::create(); | ||
const TestCase &instance = *handle; | ||
auto vec_model = std::make_shared<sixtyfps::VectorModel<int>>(std::vector<int>{1, 2}); | ||
instance.set_model(vec_model); | ||
instance.on_clicked([vec_model] { vec_model->erase(vec_model->row_count()-1); }); | ||
sixtyfps::testing::send_mouse_click(&instance, 95., 5.); | ||
assert_eq(instance.get_model()->row_count(), 1); | ||
assert(instance.get_hover()); | ||
sixtyfps::testing::send_mouse_click(&instance, 95., 5.); | ||
assert_eq(instance.get_model()->row_count(), 0); | ||
assert(!instance.get_hover()); | ||
``` | ||
|
||
```rust | ||
use sixtyfps::Model; | ||
let instance = TestCase::new(); | ||
let vec_model = std::rc::Rc::new(sixtyfps::VecModel::from(vec![1i32, 2i32])); | ||
instance.set_model(sixtyfps::ModelHandle::from(vec_model.clone() as std::rc::Rc<dyn Model<Data = i32>>)); | ||
instance.on_clicked(move || dbg!(vec_model.remove(vec_model.row_count() - 1))); | ||
sixtyfps::testing::send_mouse_click(&instance, 95., 5.); | ||
assert_eq!(instance.get_model().row_count(), 1); | ||
assert!(instance.get_hover()); | ||
sixtyfps::testing::send_mouse_click(&instance, 95., 5.); | ||
assert_eq!(instance.get_model().row_count(), 0); | ||
assert!(!instance.get_hover()); | ||
``` | ||
|
||
```js | ||
var instance = new sixtyfps.TestCase({ | ||
clicked: function() { var x = instance.model; x.pop(); instance.model = x; } | ||
}); | ||
instance.model = [1, 2]; | ||
instance.send_mouse_click(5., 5.); | ||
assert.equal(instance.model.length, 1); | ||
assert(instance.hover); | ||
instance.send_mouse_click(5., 5.); | ||
assert.equal(instance.model.length, 0); | ||
assert(!instance.hover); | ||
``` | ||
*/ |