diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-01-19 22:19:55 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-01-19 22:24:35 +0300 |
commit | 4dfccf8b7f2dfea787d7155b9c531cf56c1b33ae (patch) | |
tree | fafdad5a4ae76938a1e3e39540d92b465acaea04 /source/blender/blenkernel/intern/collection.c | |
parent | 244fb3ebe03c4feed752b9ed33afe26b393996c4 (diff) |
Collections: Fix for auto-named children when parent name is MAX_NAME
Reported via IRC by Vuk Gardašević (lijenstina).
Diffstat (limited to 'source/blender/blenkernel/intern/collection.c')
-rw-r--r-- | source/blender/blenkernel/intern/collection.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 6846683fe13..d0f89eb46e5 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -30,6 +30,7 @@ #include "BLI_ghash.h" #include "BLI_iterator.h" #include "BLI_listbase.h" +#include "BLI_math_base.h" #include "BLT_translation.h" #include "BLI_string_utils.h" @@ -86,7 +87,12 @@ SceneCollection *BKE_collection_add(ID *owner_id, SceneCollection *sc_parent, co name = BLI_sprintfN("Collection %d", BLI_listbase_count(&sc_master->scene_collections) + 1); } else { - name = BLI_sprintfN("%s %d", sc_parent->name, BLI_listbase_count(&sc_parent->scene_collections) + 1); + const int number = BLI_listbase_count(&sc_parent->scene_collections) + 1; + const int digits = integer_digits_i(number); + const int max_len = sizeof(sc_parent->name) + - 1 /* NULL terminator */ + - (1 + digits) /* " %d" */; + name = BLI_sprintfN("%.*s %d", max_len, sc_parent->name, number); } } |