diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-29 15:43:11 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-29 15:53:37 +0300 |
commit | 475a07cd0c67c4a72bb042ee5eb2af730bddb9cd (patch) | |
tree | 63300f6ec632f59a18ceef437c9114b9e3981b27 /source/blender/blenkernel/intern/library.c | |
parent | 3b6e4cf7cec8845cf839f10d241c1dcc81eb98b2 (diff) |
Fix duplicate brushes from recent startup files
Default versioning caused duplicates when the startup was re-saved.
See c305759762aa3
Diffstat (limited to 'source/blender/blenkernel/intern/library.c')
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 7392dc23119..1583f47adac 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -999,6 +999,37 @@ void BKE_main_id_flag_all(Main *bmain, const int flag, const bool value) } } +void BKE_main_id_repair_duplicate_names_listbase(ListBase *lb) +{ + int lb_len = 0; + for (ID *id = lb->first; id; id = id->next) { + if (id->lib == NULL) { + lb_len += 1; + } + } + if (lb_len <= 1) { + return; + } + + /* Fill an array because renaming sorts. */ + ID **id_array = MEM_mallocN(sizeof(*id_array) * lb_len, __func__); + GSet *gset = BLI_gset_str_new_ex(__func__, lb_len); + int i = 0; + for (ID *id = lb->first; id; id = id->next) { + if (id->lib == NULL) { + id_array[i] = id; + i++; + } + } + for (i = 0; i < lb_len; i++) { + if (!BLI_gset_add(gset, id_array[i]->name + 2)) { + new_id(lb, id_array[i], NULL); + } + } + BLI_gset_free(gset, NULL); + MEM_freeN(id_array); +} + void BKE_main_lib_objects_recalc_all(Main *bmain) { Object *ob; |