From 0418ac03703fd5dfc3c68e3ec575f473af6bf8ef Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 28 Mar 2024 16:33:01 -0400 Subject: [PATCH 1/2] Brush Assets: Remove local brushes from default startup file There was a catch I didn't expect with the outliner treestore, but solving that this way seems fine anyway. --- .../blenloader/intern/versioning_defaults.cc | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/source/blender/blenloader/intern/versioning_defaults.cc b/source/blender/blenloader/intern/versioning_defaults.cc index 7df8b08fd12..a0a751e625d 100644 --- a/source/blender/blenloader/intern/versioning_defaults.cc +++ b/source/blender/blenloader/intern/versioning_defaults.cc @@ -21,6 +21,7 @@ #include "BLI_math_rotation.h" #include "BLI_math_vector.h" #include "BLI_math_vector_types.hh" +#include "BLI_mempool.h" #include "BLI_string.h" #include "BLI_utildefines.h" @@ -904,4 +905,24 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) } } } + + { + /* Remove default brushes replaced by assets. Also remove outliner `treestore` that may point + * to brushes. Normally the treestore is updated properly but it doesn't seem to update during + * versioning code. It's not helpful anyway. */ + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, space_link, &area->spacedata) { + if (space_link->spacetype == SPACE_OUTLINER) { + SpaceOutliner *space_outliner = reinterpret_cast(space_link); + BLI_mempool_destroy(space_outliner->treestore); + space_outliner->treestore = nullptr; + } + } + } + } + LISTBASE_FOREACH_MUTABLE (Brush *, brush, &bmain->brushes) { + BKE_id_delete(bmain, brush); + } + } } -- 2.30.2 From f264897222af513a30b8bae9754344b959af7ca7 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 29 Mar 2024 11:54:33 -0400 Subject: [PATCH 2/2] Add null check for treestore --- source/blender/blenloader/intern/versioning_defaults.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/blenloader/intern/versioning_defaults.cc b/source/blender/blenloader/intern/versioning_defaults.cc index a0a751e625d..1783d56abc8 100644 --- a/source/blender/blenloader/intern/versioning_defaults.cc +++ b/source/blender/blenloader/intern/versioning_defaults.cc @@ -915,8 +915,10 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) LISTBASE_FOREACH (SpaceLink *, space_link, &area->spacedata) { if (space_link->spacetype == SPACE_OUTLINER) { SpaceOutliner *space_outliner = reinterpret_cast(space_link); - BLI_mempool_destroy(space_outliner->treestore); - space_outliner->treestore = nullptr; + if (space_outliner->treestore) { + BLI_mempool_destroy(space_outliner->treestore); + space_outliner->treestore = nullptr; + } } } } -- 2.30.2