Commit: 8ad2808fd74b4d74218deeb7e41e9d45e8fd5571
Author: Bastien Montagne
Date:   Fri Nov 13 15:34:07 2015 +0100
Branches: master
https://developer.blender.org/rB8ad2808fd74b4d74218deeb7e41e9d45e8fd5571

Tighten checks around unlinkable datablocks becoming LIB_EXTERN.

We have currently a gooseberry file 
(scenes/01_island/01_meet_franck/01_01_01_A/01_01_01_A.anim.blend)
that links against two -pre repo libs, which are hence not available for common 
mortals,
and generate warnings and placeholders during load step.

Issue is, among those missing (directly) linked datablocks, we have two 
shapekeys!

This should never happen nor be possible at all. I tried understanding how this 
could happen,
with no luck at all, best bet would be some wild/bad call to `id_us_plus()` 
over those skeys
at some point...

Anyway, this commit:
- Handles a bit better those 'cases that should never happen' at load time.
- Adds several checks in ID handling code (and save/load code) to try to detect 
where/when
  a non-linkable datablock becomes LIB_EXTERN (i.e. directly linked).

===================================================================

M       source/blender/blenkernel/intern/library.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c

===================================================================

diff --git a/source/blender/blenkernel/intern/library.c 
b/source/blender/blenkernel/intern/library.c
index f7f4f1c..a315a1f 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -89,6 +89,7 @@
 #include "BKE_global.h"
 #include "BKE_group.h"
 #include "BKE_gpencil.h"
+#include "BKE_idcode.h"
 #include "BKE_idprop.h"
 #include "BKE_image.h"
 #include "BKE_ipo.h"
@@ -152,6 +153,7 @@ void BKE_id_lib_local_paths(Main *bmain, Library *lib, ID 
*id)
 void id_lib_extern(ID *id)
 {
        if (id) {
+               BLI_assert(BKE_idcode_is_linkable(GS(id->name)));
                if (id->flag & LIB_INDIRECT) {
                        id->flag -= LIB_INDIRECT;
                        id->flag |= LIB_EXTERN;
@@ -179,10 +181,7 @@ void id_us_plus(ID *id)
        if (id) {
                BLI_assert(id->us >= 0);
                id->us++;
-               if (id->flag & LIB_INDIRECT) {
-                       id->flag -= LIB_INDIRECT;
-                       id->flag |= LIB_EXTERN;
-               }
+               id_lib_extern(id);
        }
 }
 
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 1b79a6f..a7585a5 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3382,6 +3382,8 @@ static void lib_link_key(FileData *fd, Main *main)
                        blo_do_versions_key_uidgen(key);
                }
                
+               BLI_assert((key->id.flag & LIB_EXTERN) == 0);
+
                if (key->id.flag & LIB_NEED_LINK) {
                        lib_link_animdata(fd, &key->id, key->adt);
                        
@@ -9623,6 +9625,8 @@ static ID *link_named_part(Main *mainl, FileData *fd, 
const short idcode, const
        BHead *bhead = find_bhead_from_code_name(fd, idcode, name);
        ID *id;
 
+       BLI_assert(BKE_idcode_is_linkable(idcode) && 
BKE_idcode_is_valid(idcode));
+
        if (bhead) {
                id = is_yet_read(fd, mainl, bhead);
                if (id == NULL) {
@@ -9762,6 +9766,7 @@ ID *BLO_library_link_named_part_ex(
 static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID 
*id, ID **r_id)
 {
        BHead *bhead = NULL;
+       const bool is_valid = BKE_idcode_is_linkable(GS(id->name)) || 
((id->flag & LIB_EXTERN) == 0);
 
        if (fd) {
                bhead = find_bhead_from_idname(fd, id->name);
@@ -9769,6 +9774,16 @@ static void link_id_part(ReportList *reports, FileData 
*fd, Main *mainvar, ID *i
 
        id->flag &= ~LIB_READ;
 
+       if (!is_valid) {
+               blo_reportf_wrap(
+                       reports, RPT_ERROR,
+                       TIP_("LIB: %s: '%s' is directly linked from '%s' 
(parent '%s'), but is a non-linkable datatype"),
+                       BKE_idcode_to_name(GS(id->name)),
+                       id->name + 2,
+                       mainvar->curlib->filepath,
+                       library_parent_filepath(mainvar->curlib));
+       }
+
        if (bhead) {
                id->flag |= LIB_NEED_EXPAND;
                // printf("read lib block %s\n", id->name);
@@ -9785,7 +9800,7 @@ static void link_id_part(ReportList *reports, FileData 
*fd, Main *mainvar, ID *i
 
                /* Generate a placeholder for this ID (simplified version of 
read_libblock actually...). */
                if (r_id) {
-                       *r_id = create_placeholder(mainvar, id->name, id->flag);
+                       *r_id = is_valid ? create_placeholder(mainvar, 
id->name, id->flag) : NULL;
                }
        }
 }
@@ -10055,7 +10070,9 @@ static void read_libraries(FileData *basefd, ListBase 
*mainlist)
 
                                                        
link_id_part(basefd->reports, fd, mainptr, id, &realid);
 
-                                                       BLI_assert(realid != 
NULL);
+                                                       /* realid shall never 
be NULL - unless some source file/lib is broken
+                                                        * (known case: some 
directly linked shapekey from a missing lib...). */
+                                                       /* BLI_assert(realid != 
NULL); */
 
                                                        
change_idid_adr(mainlist, basefd, id, realid);
 
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index f1f90c4..4643d2e 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -150,6 +150,7 @@
 #include "BKE_curve.h"
 #include "BKE_constraint.h"
 #include "BKE_global.h" // for G
+#include "BKE_idcode.h"
 #include "BKE_library.h" // for  set_listbasepointers
 #include "BKE_main.h"
 #include "BKE_node.h"
@@ -2922,6 +2923,11 @@ static void write_libraries(WriteData *wd, Main *main)
                        while (a--) {
                                for (id= lbarray[a]->first; id; id= id->next) {
                                        if (id->us>0 && (id->flag & 
LIB_EXTERN)) {
+                                               if 
(!BKE_idcode_is_linkable(GS(id->name))) {
+                                                       printf("ERROR: write 
file: datablock '%s' from lib '%s' is not linkable "
+                                                              "but is flagged 
as directly linked", id->name, main->curlib->filepath);
+                                                       BLI_assert(0);
+                                               }
                                                writestruct(wd, ID_ID, "ID", 1, 
id);
                                        }
                                }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to