diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index 1a80582d7f2..d2352da429a 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -395,6 +395,10 @@ BLI_INLINE bool operator==(const ListBase &a, const ListBase &b) { return BLI_listbase_equal(&a, &b); } +BLI_INLINE bool operator!=(const ListBase &a, const ListBase &b) +{ + return !(a == b); +} template T *BLI_listbase_find(const ListBase &listbase, Fn &&predicate) { diff --git a/source/blender/editors/asset/intern/asset_shelf_settings.cc b/source/blender/editors/asset/intern/asset_shelf_settings.cc index e4c84edea1c..cc31ae97166 100644 --- a/source/blender/editors/asset/intern/asset_shelf_settings.cc +++ b/source/blender/editors/asset/intern/asset_shelf_settings.cc @@ -41,9 +41,14 @@ AssetShelfSettings &AssetShelfSettings::operator=(const AssetShelfSettings &othe return *this; /* Handle self-assignment safely. */ } - /* Free existing properties. */ - BKE_asset_catalog_path_list_free(this->enabled_catalog_paths); - MEM_SAFE_FREE(this->active_catalog_path); + /* Free existing properties. Check if they point to the same memory first, #AssetShelfSettings + * might have been shallow copied before. */ + if (this->enabled_catalog_paths != other.enabled_catalog_paths) { + BKE_asset_catalog_path_list_free(this->enabled_catalog_paths); + } + if (this->active_catalog_path != other.active_catalog_path) { + MEM_SAFE_FREE(this->active_catalog_path); + } /* Copy from 'other'. */ this->asset_library_reference = other.asset_library_reference;