svn merge ^/trunk/blender -r43124:43160
[blender-staging.git] / source / blender / blenloader / intern / readfile.c
index 122e66160d61a843b05047e92a7860e546a755cc..162d3102cb6da28343b7cafd0c13e0a9d72eaf85 100644 (file)
@@ -39,6 +39,7 @@
 #include <fcntl.h> // for open
 #include <string.h> // for strrchr strncmp strstr
 #include <math.h> // for fabs
+#include <stdarg.h> /* for va_start/end */
 
 #ifndef WIN32
        #include <unistd.h> // for read close
@@ -251,6 +252,31 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname);
 static void direct_link_modifiers(FileData *fd, ListBase *lb);
 static void convert_tface_mt(FileData *fd, Main *main);
 
+/* this function ensures that reports are printed,
+ * in the case of libraray linking errors this is important!
+ *
+ * bit kludge but better then doubling up on prints,
+ * we could alternatively have a versions of a report function which foces printing - campbell
+ */
+static void BKE_reportf_wrap(ReportList *reports, ReportType type, const char *format, ...)
+{
+       char fixed_buf[1024]; /* should be long enough */
+
+       va_list args;
+
+       va_start(args, format);
+       vsnprintf(fixed_buf, sizeof(fixed_buf), format, args);
+       va_end(args);
+
+       fixed_buf[sizeof(fixed_buf) - 1] = '\0';
+
+       BKE_report(reports, type, fixed_buf);
+
+       if(G.background==0) {
+               printf("%s\n", fixed_buf);
+       }
+}
+
 static OldNewMap *oldnewmap_new(void) 
 {
        OldNewMap *onm= MEM_callocN(sizeof(*onm), "OldNewMap");
@@ -4194,8 +4220,9 @@ static void lib_link_object(FileData *fd, Main *main)
                ob= ob->id.next;
        }
 
-       if(warn)
+       if(warn) {
                BKE_report(fd->reports, RPT_WARNING, "Warning in console");
+       }
 }
 
 
@@ -4776,8 +4803,9 @@ static void lib_link_scene(FileData *fd, Main *main)
                                base->object= newlibadr_us(fd, sce->id.lib, base->object);
                                
                                if(base->object==NULL) {
-                                       BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: Object lost from scene:'%s\'\n", sce->id.name+2);
-                                       if(G.background==0) printf("LIB ERROR: base removed from scene:'%s\'\n", sce->id.name+2);
+                                       BKE_reportf_wrap(fd->reports, RPT_ERROR,
+                                                        "LIB ERROR: Object lost from scene:'%s\'\n",
+                                                        sce->id.name+2);
                                        BLI_remlink(&sce->base, base);
                                        if(base==sce->basact) sce->basact= NULL;
                                        MEM_freeN(base);
@@ -4790,7 +4818,7 @@ static void lib_link_scene(FileData *fd, Main *main)
                                if(seq->scene) {
                                        seq->scene= newlibadr(fd, sce->id.lib, seq->scene);
                                        if(seq->scene) {
-                                               seq->scene_sound = sound_scene_add_scene_sound(sce, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
+                                               seq->scene_sound = sound_scene_add_scene_sound_defaults(sce, seq);
                                        }
                                }
                                if(seq->scene_camera) seq->scene_camera= newlibadr(fd, sce->id.lib, seq->scene_camera);
@@ -4802,7 +4830,7 @@ static void lib_link_scene(FileData *fd, Main *main)
                                                seq->sound= newlibadr(fd, sce->id.lib, seq->sound);
                                        if (seq->sound) {
                                                seq->sound->id.us++;
-                                               seq->scene_sound = sound_add_scene_sound(sce, seq, seq->startdisp, seq->enddisp, seq->startofs + seq->anim_startofs);
+                                               seq->scene_sound = sound_add_scene_sound_defaults(sce, seq);
                                        }
                                }
                                seq->anim= NULL;
@@ -5877,8 +5905,9 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
        for(newmain= fd->mainlist.first; newmain; newmain= newmain->next) {
                if(newmain->curlib) {
                        if(BLI_path_cmp(newmain->curlib->filepath, lib->filepath) == 0) {
-                               printf("Fixed error in file; multiple instances of lib:\n %s\n", lib->filepath);
-                               BKE_reportf(fd->reports, RPT_WARNING, "Library '%s', '%s' had multiple instances, save and reload!", lib->name, lib->filepath);
+                               BKE_reportf_wrap(fd->reports, RPT_WARNING,
+                                                "Library '%s', '%s' had multiple instances, save and reload!",
+                                                lib->name, lib->filepath);
 
                                change_idid_adr(&fd->mainlist, fd, lib, newmain->curlib);
 //                             change_idid_adr_fd(fd, lib, newmain->curlib);
@@ -12912,6 +12941,23 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
+               {
+               /* Warn the user if he is using ["Text"] properties for Font objects */
+                       Object *ob;
+                       bProperty *prop;
+
+                       for (ob= main->object.first; ob; ob= ob->id.next) {
+                               if (ob->type == OB_FONT) {
+                                       prop = get_ob_property(ob, "Text");
+                                       if (prop) {
+                                               BKE_reportf_wrap(fd->reports, RPT_WARNING,
+                                                                "Game property name conflict in object: \"%s\".\nText objects reserve the "
+                                                                "[\"Text\"] game property to change their content through Logic Bricks.\n",
+                                                                ob->id.name+2);
+                                       }
+                               }
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -14364,8 +14410,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                if(fd==NULL) {
 
                                        /* printf and reports for now... its important users know this */
-                                       BKE_reportf(basefd->reports, RPT_INFO, "read library:  '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
-                                       if(!G.background && basefd->reports) printf("read library: '%s', '%s'\n", mainptr->curlib->filepath, mainptr->curlib->name);
+                                       BKE_reportf_wrap(basefd->reports, RPT_INFO,
+                                                        "read library:  '%s', '%s'\n",
+                                                        mainptr->curlib->filepath, mainptr->curlib->name);
 
                                        fd= blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);
                                        
@@ -14410,8 +14457,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                        else mainptr->curlib->filedata= NULL;
 
                                        if (fd==NULL) {
-                                               BKE_reportf(basefd->reports, RPT_ERROR, "Can't find lib '%s'\n", mainptr->curlib->filepath);
-                                               if(!G.background && basefd->reports) printf("ERROR: can't find lib %s \n", mainptr->curlib->filepath);
+                                               BKE_reportf_wrap(basefd->reports, RPT_ERROR,
+                                                                "Can't find lib '%s'\n",
+                                                                mainptr->curlib->filepath);
                                        }
                                }
                                if(fd) {
@@ -14428,8 +14476,10 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
 
                                                                append_id_part(fd, mainptr, id, &realid);
                                                                if (!realid) {
-                                                                       BKE_reportf(fd->reports, RPT_ERROR, "LIB ERROR: %s:'%s' missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-                                                                       if(!G.background && basefd->reports) printf("LIB ERROR: %s:'%s' missing from '%s'\n", BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
+                                                                       BKE_reportf_wrap(fd->reports, RPT_ERROR,
+                                                                                        "LIB ERROR: %s:'%s' missing from '%s'\n",
+                                                                                        BKE_idcode_to_name(GS(id->name)),
+                                                                                        id->name+2, mainptr->curlib->filepath);
                                                                }
                                                                
                                                                change_idid_adr(mainlist, basefd, id, realid);
@@ -14465,13 +14515,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                ID *idn= id->next;
                                if(id->flag & LIB_READ) {
                                        BLI_remlink(lbarray[a], id);
-                                       BKE_reportf(basefd->reports, RPT_ERROR,
-                                                   "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n",
-                                                   BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-                                       if (!G.background && basefd->reports) {
-                                               printf("LIB ERROR: %s:'%s' unread libblock missing from '%s'\n",
-                                                      BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
-                                       }
+                                       BKE_reportf_wrap(basefd->reports, RPT_ERROR,
+                                                        "LIB ERROR: %s:'%s' unread libblock missing from '%s'\n",
+                                                        BKE_idcode_to_name(GS(id->name)), id->name+2, mainptr->curlib->filepath);
                                        change_idid_adr(mainlist, basefd, id, NULL);
 
                                        MEM_freeN(id);