Fix #21577: incorrect camera selected when loading file without UI.
[blender.git] / source / blender / blenloader / intern / readfile.c
index c6e3ef4767f6167f51978ab22d99e355dc4c3261..1f6d36dc95710cacf469cbd93e4ee0ff988f2e29 100644 (file)
 #include "BKE_group.h"
 #include "BKE_image.h"
 #include "BKE_lattice.h"
-#include "BKE_library.h" // for wich_libbase
+#include "BKE_library.h" // for which_libbase
 #include "BKE_main.h" // for Main
 #include "BKE_mesh.h" // for ME_ defines (patching)
 #include "BKE_modifier.h"
@@ -429,7 +429,7 @@ static void split_libdata(ListBase *lb, Main *first)
                        mainvar= first;
                        while(mainvar) {
                                if(mainvar->curlib==id->lib) {
-                                       lbn= wich_libbase(mainvar, GS(id->name));
+                                       lbn= which_libbase(mainvar, GS(id->name));
                                        BLI_remlink(lb, id);
                                        BLI_addtail(lbn, id);
                                        break;
@@ -3038,6 +3038,7 @@ static void direct_link_particlesettings(FileData *fd, ParticleSettings *part)
        link_list(fd, &part->dupliweights);
 
        part->boids= newdataadr(fd, part->boids);
+       part->fluid= newdataadr(fd, part->fluid);
 
        if(part->boids) {
                BoidState *state;
@@ -3438,7 +3439,11 @@ static void lib_link_object(FileData *fd, Main *main)
                                if(ob->proxy->id.lib==NULL) {
                                        ob->proxy->proxy_from= NULL;
                                        ob->proxy= NULL;
-                                       printf("Proxy lost from  object %s lib %s\n", ob->id.name+2, ob->id.lib->name);
+                                       
+                                       if (ob->id.lib)
+                                               printf("Proxy lost from  object %s lib %s\n", ob->id.name+2, ob->id.lib->name);
+                                       else
+                                               printf("Proxy lost from  object %s lib <NONE>\n", ob->id.name+2);
                                }
                                else {
                                        /* this triggers object_update to always use a copy */
@@ -4609,6 +4614,11 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                SpaceImage *sima= (SpaceImage *)sl;
 
                                                sima->image= newlibadr_us(fd, sc->id.lib, sima->image);
+                                               
+                                               /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
+                                                * so fingers crossed this works fine!
+                                                */
+                                               sima->gpd= newlibadr_us(fd, sc->id.lib, sima->gpd);
                                        }
                                        else if(sl->spacetype==SPACE_NLA){
                                                SpaceNla *snla= (SpaceNla *)sl;
@@ -4684,7 +4694,7 @@ static void *restore_pointer_by_name(Main *mainp, ID *id, int user)
 {
                
        if(id) {
-               ListBase *lb= wich_libbase(mainp, GS(id->name));
+               ListBase *lb= which_libbase(mainp, GS(id->name));
                
                if(lb) {        // there's still risk of checking corrupt mem (freed Ids in oops)
                        ID *idn= lb->first;
@@ -4747,7 +4757,10 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        View3D *v3d= (View3D*) sl;
                                        BGpic *bgpic;
                                        
-                                       v3d->camera= restore_pointer_by_name(newmain, (ID *)v3d->camera, 1);
+                                       if(v3d->scenelock)
+                                               v3d->camera= NULL; /* always get from scene */
+                                       else
+                                               v3d->camera= restore_pointer_by_name(newmain, (ID *)v3d->camera, 1);
                                        if(v3d->camera==NULL)
                                                v3d->camera= sc->scene->camera;
                                        v3d->ob_centre= restore_pointer_by_name(newmain, (ID *)v3d->ob_centre, 1);
@@ -4823,6 +4836,11 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        SpaceImage *sima= (SpaceImage *)sl;
 
                                        sima->image= restore_pointer_by_name(newmain, (ID *)sima->image, 1);
+                                       
+                                       /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
+                                        * so assume that here we're doing for undo only...
+                                        */
+                                       sima->gpd= restore_pointer_by_name(newmain, (ID *)sima->gpd, 1);
                                }
                                else if(sl->spacetype==SPACE_NLA){
                                        SpaceNla *snla= (SpaceNla *)sl;
@@ -5085,13 +5103,18 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                SpaceImage *sima= (SpaceImage *)sl;
                                
                                sima->cumap= newdataadr(fd, sima->cumap);
-                               sima->gpd= newdataadr(fd, sima->gpd);
-                               if (sima->gpd)
-                                       direct_link_gpencil(fd, sima->gpd);
                                if(sima->cumap)
                                        direct_link_curvemapping(fd, sima->cumap);
+                               
                                sima->iuser.scene= NULL;
                                sima->iuser.ok= 1;
+                               
+                               /* WARNING: gpencil data is no longer stored directly in sima after 2.5 
+                                * so sacrifice a few old files for now to avoid crashes with new files!
+                                */
+                               //sima->gpd= newdataadr(fd, sima->gpd);
+                               //if (sima->gpd)
+                               //      direct_link_gpencil(fd, sima->gpd);
                        }
                        else if(sl->spacetype==SPACE_NODE) {
                                SpaceNode *snode= (SpaceNode *)sl;
@@ -5377,10 +5400,10 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
        
        /* do after read_struct, for dna reconstruct */
        if(bhead->code==ID_ID) {
-               lb= wich_libbase(main, GS(id->name));
+               lb= which_libbase(main, GS(id->name));
        }
        else {
-               lb= wich_libbase(main, bhead->code);
+               lb= which_libbase(main, bhead->code);
        }
        
        BLI_addtail(lb, id);
@@ -10959,8 +10982,8 @@ char *bhead_id_name(FileData *fd, BHead *bhead)
 static ID *is_yet_read(FileData *fd, Main *mainvar, BHead *bhead)
 {
        const char *idname= bhead_id_name(fd, bhead);
-       /* wich_libbase can be NULL, intentionally not using idname+2 */
-       return BLI_findstring(wich_libbase(mainvar, GS(idname)), idname, offsetof(ID, name));
+       /* which_libbase can be NULL, intentionally not using idname+2 */
+       return BLI_findstring(which_libbase(mainvar, GS(idname)), idname, offsetof(ID, name));
 }
 
 static void expand_doit(FileData *fd, Main *mainvar, void *old)
@@ -12130,8 +12153,8 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                if(fd==NULL) {
 
                                        /* printf and reports for now... its important users know this */
-                                       printf("read library: %s\n", mainptr->curlib->name);
-                                       BKE_reportf(basefd->reports, RPT_INFO, "read library: '%s'\n", mainptr->curlib->name);
+                                       printf("read library: '%s', '%s'\n", mainptr->curlib->filename, mainptr->curlib->name);
+                                       BKE_reportf(basefd->reports, RPT_INFO, "read library:  '%s', '%s'\n", mainptr->curlib->filename, mainptr->curlib->name);
 
                                        fd= blo_openblenderfile(mainptr->curlib->filename, basefd->reports);