Fix #21577: incorrect camera selected when loading file without UI.
[blender.git] / source / blender / blenloader / intern / readfile.c
index b23b0edb285828db2a3eb2f0c0b96995c3278ada..1f6d36dc95710cacf469cbd93e4ee0ff988f2e29 100644 (file)
@@ -3439,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;
                                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 */
                                }
                                else {
                                        /* this triggers object_update to always use a copy */
@@ -4610,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);
                                                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;
                                        }
                                        else if(sl->spacetype==SPACE_NLA){
                                                SpaceNla *snla= (SpaceNla *)sl;
@@ -4748,7 +4757,10 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                                        View3D *v3d= (View3D*) sl;
                                        BGpic *bgpic;
                                        
                                        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);
                                        if(v3d->camera==NULL)
                                                v3d->camera= sc->scene->camera;
                                        v3d->ob_centre= restore_pointer_by_name(newmain, (ID *)v3d->ob_centre, 1);
@@ -4824,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);
                                        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;
                                }
                                else if(sl->spacetype==SPACE_NLA){
                                        SpaceNla *snla= (SpaceNla *)sl;
@@ -5086,13 +5103,18 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                                SpaceImage *sima= (SpaceImage *)sl;
                                
                                sima->cumap= newdataadr(fd, sima->cumap);
                                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);
                                if(sima->cumap)
                                        direct_link_curvemapping(fd, sima->cumap);
+                               
                                sima->iuser.scene= NULL;
                                sima->iuser.ok= 1;
                                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;
                        }
                        else if(sl->spacetype==SPACE_NODE) {
                                SpaceNode *snode= (SpaceNode *)sl;