Merge branch 'master' into blender2.8
[blender.git] / source / blender / blenkernel / intern / library.c
index 4721955af439f4556c6fccba379149b6276fd93b..76b8aa2d446ee2d2170189491751562cc04e4f2b 100644 (file)
@@ -1120,23 +1120,21 @@ void *BKE_libblock_alloc_notest(short type)
  */
 void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int flag)
 {
-       ID *id = NULL;
-
        BLI_assert((flag & LIB_ID_CREATE_NO_ALLOCATE) == 0);
-       
-       id = BKE_libblock_alloc_notest(type);
 
-       if ((flag & LIB_ID_CREATE_NO_MAIN) != 0) {
-               id->tag |= LIB_TAG_NO_MAIN;
-       }
-       if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0) {
-               id->tag |= LIB_TAG_NO_USER_REFCOUNT;
-       }
+       ID *id = BKE_libblock_alloc_notest(type);
 
        if (id) {
+               if ((flag & LIB_ID_CREATE_NO_MAIN) != 0) {
+                       id->tag |= LIB_TAG_NO_MAIN;
+               }
+               if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0) {
+                       id->tag |= LIB_TAG_NO_USER_REFCOUNT;
+               }
+
                id->icon_id = 0;
-               *( (short *)id->name) = type;
-               if ((flag & LIB_ID_FREE_NO_USER_REFCOUNT) == 0) {
+               *((short *)id->name) = type;
+               if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
                        id->us = 1;
                }
                if ((flag & LIB_ID_CREATE_NO_MAIN) == 0) {
@@ -1153,6 +1151,9 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int fl
                                DEG_id_type_tag(bmain, type);
                        }
                }
+               else {
+                       BLI_strncpy(id->name + 2, name, sizeof(id->name) - 2);
+               }
        }
 
        return id;