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.
This commit is contained in:
Olivier Goffart 2021-09-08 09:36:38 +02:00 committed by Olivier Goffart
parent e8c1fccbbc
commit fafcbfde2c
5 changed files with 99 additions and 4 deletions

View file

@ -403,6 +403,12 @@ inline bool operator!=(const LayoutInfo &a, const LayoutInfo &b)
}
namespace private_api {
/// Access the layout cache of an item within a repeater
inline float layout_cache_access(const SharedVector<float> &cache, int offset, int repeater_index) {
size_t idx = size_t(cache[offset]) + repeater_index * 2;
return idx < cache.size() ? cache[idx] : 0;
}
// models
struct AbstractRepeaterView
{