Collections: Fix for auto-named children when parent name is MAX_NAME

Reported via IRC by Vuk Gardašević (lijenstina).
This commit is contained in:
Dalai Felinto 2018-01-19 17:19:55 -02:00
parent 244fb3ebe0
commit 4dfccf8b7f
1 changed files with 7 additions and 1 deletions

View File

@ -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);
}
}