From 8a9dedf829544e30f822bcb016a9c134af6979e5 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 23 Dec 2020 16:01:24 +0100 Subject: Workaround T84084: Assert/crash when undoing from Sculpt mode to Object one. Disclaimer: This workaround avoids crashing with current state of the code and is only committed as temporary band-aid until we can assess the full issue and decide if/how it needs to be adressed. --- .../blender/blenkernel/intern/multires_reshape_ccg.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'source/blender/blenkernel/intern/multires_reshape_ccg.c') diff --git a/source/blender/blenkernel/intern/multires_reshape_ccg.c b/source/blender/blenkernel/intern/multires_reshape_ccg.c index 55f7766c878..aa003909bb0 100644 --- a/source/blender/blenkernel/intern/multires_reshape_ccg.c +++ b/source/blender/blenkernel/intern/multires_reshape_ccg.c @@ -61,8 +61,24 @@ bool multires_reshape_assign_final_coords_from_ccg(const MultiresReshapeContext sizeof(float[3])); if (reshape_level_key.has_mask) { - BLI_assert(grid_element.mask != NULL); - *grid_element.mask = *CCG_grid_elem_mask(&reshape_level_key, ccg_grid, x, y); + /* Assert about a non-NULL `grid_element.mask` may fail here, this code may be called + * from cleanup code during COW evaluation phase by depsgraph (e.g. + * `object_update_from_subsurf_ccg` call in `BKE_object_free_derived_caches`). + * + * `reshape_level_key.has_mask` is ultimately set from MultiRes modifier apply code + * (through `multires_as_ccg` -> `multires_ccg_settings_init`), when object is in sculpt + * mode only, and there is matching loop cdlayer. + * + * `grid_element.mask` is directly set from existing matching loop cdlayer during + * initialization of `MultiresReshapeContext` struct. + * + * Since ccg data is preserved during undos, we may end up with a state where there is no + * mask data in mesh loops' cdlayer, while ccg's `has_mask` is still set to true. + */ + // BLI_assert(grid_element.mask != NULL); + if (grid_element.mask != NULL) { + *grid_element.mask = *CCG_grid_elem_mask(&reshape_level_key, ccg_grid, x, y); + } } } } -- cgit v1.2.3