armature ghost stepsize was not initialized, Aligorith: can you check this is correct?
[blender.git] / source / blender / blenloader / intern / readfile.c
index 114ec9095b15025baac4171e67b1f4efd487b1fe..88c120dc1e15176b5e1609df0cd0eb02481230ce 100644 (file)
 
 #include "MEM_guardedalloc.h"
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "BLI_storage_types.h" // for relname flags
 
 #include "BKE_animsys.h"
+#include "BKE_anim.h"
 #include "BKE_action.h"
 #include "BKE_armature.h"
 #include "BKE_brush.h"
 #include "BKE_report.h"
 #include "BKE_sca.h" // for init_actuator
 #include "BKE_scene.h"
+#include "BKE_screen.h"
 #include "BKE_softbody.h"      // sbNew()
 #include "BKE_bullet.h"                // bsbNew()
-#include "BKE_sequence.h"
+#include "BKE_sequencer.h"
 #include "BKE_texture.h" // for open_plugin_tex
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
 #include "BKE_idprop.h"
@@ -977,7 +979,7 @@ FileData *blo_openblenderfile(char *name, ReportList *reports)
                fd->read = fd_read_gzip_from_file;
 
                /* needed for library_append and read_libraries */
-               BLI_strncpy(fd->filename, name, sizeof(fd->filename));
+               BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
 
                return blo_decode_and_check(fd, reports);
        }
@@ -1702,6 +1704,9 @@ static void lib_link_fcurves(FileData *fd, ID *id, ListBase *list)
 {
        FCurve *fcu;
        
+       if (list == NULL)
+               return;
+       
        /* relink ID-block references... */
        for (fcu= list->first; fcu; fcu= fcu->next) {
                /* driver data */
@@ -1848,6 +1853,9 @@ static void lib_link_nladata_strips(FileData *fd, ID *id, ListBase *list)
                /* check strip's children */
                lib_link_nladata_strips(fd, id, &strip->strips);
                
+               /* check strip's F-Curves */
+               lib_link_fcurves(fd, id, &strip->fcurves);
+               
                /* reassign the counted-reference to action */
                strip->act = newlibadr_us(fd, id->lib, strip->act);
        }
@@ -1974,6 +1982,19 @@ static void direct_link_animdata(FileData *fd, AnimData *adt)
        adt->actstrip= NULL;
 }      
 
+/* ************ READ MOTION PATHS *************** */
+
+/* direct data for cache */
+static void direct_link_motionpath(FileData *fd, bMotionPath *mpath)
+{
+       /* sanity check */
+       if (mpath == NULL)
+               return;
+       
+       /* relink points cache */
+       mpath->points= newdataadr(fd, mpath->points);
+}
+
 /* ************ READ NODE TREE *************** */
 
 /* singe node tree (also used for material/scene trees), ntree is not NULL */
@@ -1983,6 +2004,8 @@ static void lib_link_ntree(FileData *fd, ID *id, bNodeTree *ntree)
        
        if(ntree->adt) lib_link_animdata(fd, &ntree->id, ntree->adt);
        
+       ntree->gpd= newlibadr_us(fd, id->lib, ntree->gpd);
+       
        for(node= ntree->nodes.first; node; node= node->next)
                node->id= newlibadr_us(fd, id->lib, node->id);
 }
@@ -2265,6 +2288,20 @@ static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist)
                                data->target = newlibadr(fd, id->lib, data->target);
                        }
                        break;
+               case CONSTRAINT_TYPE_DAMPTRACK:
+                       {
+                               bDampTrackConstraint *data;
+                               data= ((bDampTrackConstraint*)con->data);
+                               data->tar = newlibadr(fd, id->lib, data->tar);
+                       }
+                       break;
+               case CONSTRAINT_TYPE_SPLINEIK:
+                       {
+                               bSplineIKConstraint *data;
+                               data= ((bSplineIKConstraint*)con->data);
+                               data->tar = newlibadr(fd, id->lib, data->tar);
+                       }
+                       break;
                case CONSTRAINT_TYPE_NULL:
                        break;
                }
@@ -2288,6 +2325,11 @@ static void direct_link_constraints(FileData *fd, ListBase *lb)
                        if (data->prop)
                                IDP_DirectLinkProperty(data->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
                }
+               else if (cons->type == CONSTRAINT_TYPE_SPLINEIK) {
+                       bSplineIKConstraint *data= cons->data;
+                       
+                       data->points= newdataadr(fd, data->points);
+               }
        }
 }
 
@@ -2314,7 +2356,7 @@ static void lib_link_pose(FileData *fd, Object *ob, bPose *pose)
                        rebuild= 1;
                else if(ob->id.lib==NULL && arm->id.lib) {
                        /* local pose selection copied to armature, bit hackish */
-                       pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE);
+                       pchan->bone->flag &= ~BONE_SELECTED;
                        pchan->bone->flag |= pchan->selectflag;
                }
        }
@@ -2345,12 +2387,16 @@ static void direct_link_bones(FileData *fd, Bone* bone)
        Bone    *child;
 
        bone->parent= newdataadr(fd, bone->parent);
+       bone->prop= newdataadr(fd, bone->prop);
+       if(bone->prop)
+               IDP_DirectLinkProperty(bone->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+               
+       bone->flag &= ~BONE_DRAW_ACTIVE;
 
        link_list(fd, &bone->childbase);
 
-       for (child=bone->childbase.first; child; child=child->next) {
+       for(child=bone->childbase.first; child; child=child->next)
                direct_link_bones(fd, child);
-       }
 }
 
 static void direct_link_armature(FileData *fd, bArmature *arm)
@@ -2360,13 +2406,18 @@ static void direct_link_armature(FileData *fd, bArmature *arm)
        link_list(fd, &arm->bonebase);
        arm->edbo= NULL;
        arm->sketch = NULL;
+       
        arm->adt= newdataadr(fd, arm->adt);
+       direct_link_animdata(fd, arm->adt);
        
        bone=arm->bonebase.first;
        while (bone) {
                direct_link_bones(fd, bone);
                bone=bone->next;
        }
+
+       arm->act_bone= newdataadr(fd, arm->act_bone);
+       arm->act_edbone= NULL;
 }
 
 /* ************ READ CAMERA ***************** */
@@ -2861,10 +2912,8 @@ static void lib_link_texture(FileData *fd, Main *main)
                        tex->ima= newlibadr_us(fd, tex->id.lib, tex->ima);
                        tex->ipo= newlibadr_us(fd, tex->id.lib, tex->ipo);
                        if(tex->env) tex->env->object= newlibadr(fd, tex->id.lib, tex->env->object);
-                       if(tex->pd) {
+                       if(tex->pd)
                                tex->pd->object= newlibadr(fd, tex->id.lib, tex->pd->object);
-                               tex->pd->psys= newlibadr(fd, tex->id.lib, tex->pd->psys);
-                       }
                        if(tex->vd) tex->vd->object= newlibadr(fd, tex->id.lib, tex->vd->object);
 
                        if(tex->nodetree)
@@ -3030,9 +3079,16 @@ static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointC
        }
 }
 
+void lib_link_partdeflect(FileData *fd, ID *id, PartDeflect *pd)
+{
+       if(pd && pd->tex)
+               pd->tex=newlibadr_us(fd, id->lib, pd->tex);
+}
+
 static void lib_link_particlesettings(FileData *fd, Main *main)
 {
        ParticleSettings *part;
+       ParticleDupliWeight *dw;
 
        part= main->particle.first;
        while(part) {
@@ -3044,6 +3100,17 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
                        part->dup_group = newlibadr(fd, part->id.lib, part->dup_group);
                        part->eff_group = newlibadr(fd, part->id.lib, part->eff_group);
                        part->bb_ob = newlibadr(fd, part->id.lib, part->bb_ob);
+
+                       lib_link_partdeflect(fd, &part->id, part->pd);
+                       lib_link_partdeflect(fd, &part->id, part->pd2);
+
+                       if(part->effector_weights)
+                               part->effector_weights->group = newlibadr(fd, part->id.lib, part->effector_weights->group);
+
+                       dw = part->dupliweights.first;
+                       for(; dw; dw=dw->next)
+                               dw->ob = newlibadr(fd, part->id.lib, dw->ob);
+
                        if(part->boids) {
                                BoidState *state = part->boids->states.first;
                                BoidRule *rule;
@@ -3073,12 +3140,26 @@ static void lib_link_particlesettings(FileData *fd, Main *main)
        }
 }
 
+static void direct_link_partdeflect(PartDeflect *pd)
+{
+       if(pd) pd->rng=NULL;
+}
+
 static void direct_link_particlesettings(FileData *fd, ParticleSettings *part)
 {
        part->adt= newdataadr(fd, part->adt);
        part->pd= newdataadr(fd, part->pd);
        part->pd2= newdataadr(fd, part->pd2);
 
+       direct_link_partdeflect(part->pd);
+       direct_link_partdeflect(part->pd2);
+
+       part->effector_weights = newdataadr(fd, part->effector_weights);
+       if(!part->effector_weights)
+               part->effector_weights = BKE_add_effector_weights(part->eff_group);
+
+       link_list(fd, &part->dupliweights);
+
        part->boids= newdataadr(fd, part->boids);
 
        if(part->boids) {
@@ -3155,18 +3236,17 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
                }
 
 
-               psys->child=newdataadr(fd,psys->child);
-               psys->effectors.first=psys->effectors.last=0;
+               psys->child = newdataadr(fd,psys->child);
+               psys->effectors = NULL;
 
                link_list(fd, &psys->targets);
 
                psys->edit = NULL;
                psys->free_edit = NULL;
-               psys->pathcache = 0;
-               psys->childcache = 0;
-               psys->pathcachebufs.first = psys->pathcachebufs.last = 0;
-               psys->childcachebufs.first = psys->childcachebufs.last = 0;
-               psys->reactevents.first = psys->reactevents.last = 0;
+               psys->pathcache = NULL;
+               psys->childcache = NULL;
+               psys->pathcachebufs.first = psys->pathcachebufs.last = NULL;
+               psys->childcachebufs.first = psys->childcachebufs.last = NULL;
                psys->frand = NULL;
                psys->pdd = NULL;
 
@@ -3270,14 +3350,14 @@ static void direct_link_dverts(FileData *fd, int count, MDeformVert *mdverts)
        }
 }
 
-static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps)
+static void direct_link_mdisps(FileData *fd, int count, MDisps *mdisps, int external)
 {
        if(mdisps) {
                int i;
 
                for(i = 0; i < count; ++i) {
                        mdisps[i].disps = newdataadr(fd, mdisps[i].disps);
-                       if(!mdisps[i].disps)
+                       if(!external && !mdisps[i].disps)
                                mdisps[i].totdisp = 0;
                }
        }       
@@ -3288,14 +3368,18 @@ static void direct_link_customdata(FileData *fd, CustomData *data, int count)
        int i = 0;
 
        data->layers= newdataadr(fd, data->layers);
+       data->external= newdataadr(fd, data->external);
 
        while (i < data->totlayer) {
                CustomDataLayer *layer = &data->layers[i];
 
+               if(layer->flag & CD_FLAG_EXTERNAL)
+                       layer->flag &= ~CD_FLAG_IN_MEMORY;
+
                if (CustomData_verify_versions(data, i)) {
                        layer->data = newdataadr(fd, layer->data);
                        if(layer->type == CD_MDISPS)
-                               direct_link_mdisps(fd, count, layer->data);
+                               direct_link_mdisps(fd, count, layer->data, layer->flag & CD_FLAG_EXTERNAL);
                        i++;
                }
        }
@@ -3482,7 +3566,7 @@ static void lib_link_object(FileData *fd, Main *main)
                                ob->type= OB_EMPTY;
                                warn= 1;
                                if(ob->id.lib) printf("Can't find obdata of %s lib %s\n", ob->id.name+2, ob->id.lib->name);
-                               else printf("Object %s lost data.", ob->id.name+2);
+                               else printf("Object %s lost data.\n", ob->id.name+2);
                                
                                if(ob->pose) {
                                        free_pose(ob->pose);
@@ -3640,13 +3724,26 @@ static void lib_link_object(FileData *fd, Main *main)
                                        smd->domain->coll_group = newlibadr_us(fd, ob->id.lib, smd->domain->coll_group);
                                        smd->domain->eff_group = newlibadr_us(fd, ob->id.lib, smd->domain->eff_group);
                                        smd->domain->fluid_group = newlibadr_us(fd, ob->id.lib, smd->domain->fluid_group);
+
+                                       smd->domain->effector_weights->group = newlibadr(fd, ob->id.lib, smd->domain->effector_weights->group);
+                               }
+                       }
+
+                       {
+                               ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
+                               
+                               if(clmd) 
+                               {
+                                       clmd->sim_parms->effector_weights->group = newlibadr(fd, ob->id.lib, clmd->sim_parms->effector_weights->group);
                                }
                        }
                        
                        /* texture field */
                        if(ob->pd)
-                               if(ob->pd->tex)
-                                       ob->pd->tex=newlibadr_us(fd, ob->id.lib, ob->pd->tex);
+                               lib_link_partdeflect(fd, &ob->id, ob->pd);
+
+                       if(ob->soft)
+                               ob->soft->effector_weights->group = newlibadr(fd, ob->id.lib, ob->soft->effector_weights->group);
 
                        lib_link_particlesystems(fd, ob, &ob->id, &ob->particlesystem);
                        lib_link_modifiers(fd, ob);
@@ -3680,6 +3777,10 @@ static void direct_link_pose(FileData *fd, bPose *pose)
                if (pchan->prop)
                        IDP_DirectLinkProperty(pchan->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
                
+               pchan->mpath= newdataadr(fd, pchan->mpath);
+               if (pchan->mpath)
+                       direct_link_motionpath(fd, pchan->mpath);
+               
                pchan->iktree.first= pchan->iktree.last= NULL;
                pchan->path= NULL;
        }
@@ -3726,7 +3827,13 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        if(clmd->sim_parms) {
                                if(clmd->sim_parms->presets > 10)
                                        clmd->sim_parms->presets = 0;
+
+                               clmd->sim_parms->reset = 0;
                        }
+
+                       clmd->sim_parms->effector_weights = newdataadr(fd, clmd->sim_parms->effector_weights);
+                       if(!clmd->sim_parms->effector_weights)
+                               clmd->sim_parms->effector_weights = BKE_add_effector_weights(NULL);
                        
                }
                else if (md->type==eModifierType_Fluidsim) {
@@ -3752,6 +3859,10 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                                smd->domain->tex_shadow = NULL;
                                smd->domain->tex_wt = NULL;
 
+                               smd->domain->effector_weights = newdataadr(fd, smd->domain->effector_weights);
+                               if(!smd->domain->effector_weights)
+                                       smd->domain->effector_weights = BKE_add_effector_weights(NULL);
+
                                direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0]));
                                direct_link_pointcache_list(fd, &(smd->domain->ptcaches[1]), &(smd->domain->point_cache[1]));
                        }
@@ -3767,12 +3878,15 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        {
                                smd->flow = NULL;
                                smd->domain = NULL;
-                               smd->coll = NULL;
-                               /*
                                smd->coll = newdataadr(fd, smd->coll);
-                               smd->coll->points = NULL;
-                               smd->coll->numpoints = 0;
-                               */
+                               if(smd->coll)
+                               {
+                                       smd->coll->points = NULL;
+                                       smd->coll->numpoints = 0;
+                               }
+                               else
+                                       smd->type = 0;
+
                        }
                }
                else if (md->type==eModifierType_Collision) {
@@ -3795,7 +3909,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                        collmd->current_x = NULL;
                        collmd->current_xnew = NULL;
                        collmd->current_v = NULL;
-                       collmd->time = -1;
+                       collmd->time = -1000;
                        collmd->numverts = 0;
                        collmd->bvhtree = NULL;
                        collmd->mfaces = NULL;
@@ -3854,12 +3968,6 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                                                SWITCH_INT(mmd->dynverts[a])
                        }
                }
-               else if (md->type==eModifierType_Multires) {
-                       MultiresModifierData *mmd = (MultiresModifierData*) md;
-                       
-                       mmd->undo_verts = newdataadr(fd, mmd->undo_verts);
-                       mmd->undo_signal = !!mmd->undo_verts;
-               }
        }
 }
 
@@ -3874,7 +3982,10 @@ static void direct_link_object(FileData *fd, Object *ob)
        
        /* weak weak... this was only meant as draw flag, now is used in give_base too */
        ob->flag &= ~OB_FROMGROUP;
-
+       
+       /* editmode doesn't get saved in files, so should get cleared when reloading... */
+       ob->mode &= ~(OB_MODE_EDIT|OB_MODE_PARTICLE_EDIT);
+       
        ob->disp.first=ob->disp.last= NULL;
        
        ob->adt= newdataadr(fd, ob->adt);
@@ -3882,6 +3993,10 @@ static void direct_link_object(FileData *fd, Object *ob)
        
        ob->pose= newdataadr(fd, ob->pose);
        direct_link_pose(fd, ob->pose);
+       
+       ob->mpath= newdataadr(fd, ob->mpath);
+       if (ob->mpath)
+               direct_link_motionpath(fd, ob->mpath);
 
        link_list(fd, &ob->defbase);
 // XXX depreceated - old animation system <<<
@@ -3948,6 +4063,7 @@ static void direct_link_object(FileData *fd, Object *ob)
        }
 
        ob->pd= newdataadr(fd, ob->pd);
+       direct_link_partdeflect(ob->pd);
        ob->soft= newdataadr(fd, ob->soft);
        if(ob->soft) {
                SoftBody *sb= ob->soft;         
@@ -3965,6 +4081,10 @@ static void direct_link_object(FileData *fd, Object *ob)
                        }
                }
 
+               sb->effector_weights = newdataadr(fd, sb->effector_weights);
+               if(!sb->effector_weights)
+                       sb->effector_weights = BKE_add_effector_weights(NULL);
+
                direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache);
        }
        ob->bsoft= newdataadr(fd, ob->bsoft);
@@ -4043,6 +4163,8 @@ static void direct_link_object(FileData *fd, Object *ob)
 
                BLI_addhead(&ob->modifiers, hmd);
                BLI_remlink(&ob->hooks, hook);
+               
+               modifier_unique_name(&ob->modifiers, (ModifierData*)hmd);
 
                MEM_freeN(hook);
        }
@@ -4065,7 +4187,7 @@ static void composite_patch(bNodeTree *ntree, Scene *scene)
        bNode *node;
        
        for(node= ntree->nodes.first; node; node= node->next)
-               if(node->id==NULL && ELEM(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE))
+               if(node->id==NULL && ELEM3(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS))
                        node->id= &scene->id;
 }
 
@@ -4084,6 +4206,7 @@ static void lib_link_scene(FileData *fd, Main *main)
        Base *base, *next;
        Sequence *seq;
        SceneRenderLayer *srl;
+       TimeMarker *marker;
        
        sce= main->scene.first;
        while(sce) {
@@ -4114,9 +4237,6 @@ static void lib_link_scene(FileData *fd, Main *main)
                                /* base->object= newlibadr_us(fd, sce->id.lib, base->object); */
                                base->object= newlibadr_us(fd, sce->id.lib, base->object);
                                
-                               /* when save during radiotool, needs cleared */
-                               base->flag &= ~OB_RADIO;
-                               
                                if(base->object==NULL) {
                                        printf("LIB ERROR: base removed\n");
                                        BLI_remlink(&sce->base, base);
@@ -4124,16 +4244,12 @@ static void lib_link_scene(FileData *fd, Main *main)
                                        MEM_freeN(base);
                                }
                        }
-                       
-                       if (sce->ed) {
-                               Editing *ed= sce->ed;
-                               ed->act_seq= NULL; //   ed->act_seq=  newlibadr(fd, ed->act_seq); // FIXME
-                       }
 
                        SEQ_BEGIN(sce->ed, seq) {
                                if(seq->ipo) seq->ipo= newlibadr_us(fd, sce->id.lib, seq->ipo);
                                if(seq->scene) seq->scene= newlibadr(fd, sce->id.lib, seq->scene);
                                if(seq->sound) {
+                                       seq->sound_handle= NULL;
                                        if(seq->type == SEQ_HD_SOUND)
                                                seq->type = SEQ_SOUND;
                                        else
@@ -4146,6 +4262,17 @@ static void lib_link_scene(FileData *fd, Main *main)
                                seq->anim= 0;
                        }
                        SEQ_END
+
+#ifdef DURIAN_CAMERA_SWITCH
+                       for(marker= sce->markers.first; marker; marker= marker->next) {
+                               if(marker->camera) {
+                                       marker->camera= newlibadr(fd, sce->id.lib, marker->camera);
+                               }
+                       }
+#endif
+
+                       if(sce->ed)
+                               seq_update_muting(sce->ed);
                        
                        if(sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
@@ -4180,9 +4307,14 @@ static void link_recurs_seq(FileData *fd, ListBase *lb)
 
 static void direct_link_paint(FileData *fd, Paint **paint)
 {
-       (*paint)= newdataadr(fd, (*paint));
-       if(*paint)
-               (*paint)->brushes= newdataadr(fd, (*paint)->brushes);
+       Paint *p;
+
+       p= (*paint)= newdataadr(fd, (*paint));
+       if(p) {
+               p->paint_cursor= NULL;
+               p->brushes= newdataadr(fd, p->brushes);
+               test_pointer_array(fd, (void**)&p->brushes);
+       }
 }
 
 static void direct_link_scene(FileData *fd, Scene *sce)
@@ -4218,6 +4350,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
 
                sce->toolsettings->imapaint.paint.brushes= newdataadr(fd, sce->toolsettings->imapaint.paint.brushes);
+               test_pointer_array(fd, (void**)&sce->toolsettings->imapaint.paint.brushes);
 
                sce->toolsettings->imapaint.paintcursor= NULL;
                sce->toolsettings->particle.paintcursor= NULL;
@@ -4227,7 +4360,8 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                ListBase *old_seqbasep= &((Editing *)sce->ed)->seqbase;
                
                ed= sce->ed= newdataadr(fd, sce->ed);
-               ed->act_seq= NULL; //           ed->act_seq=  newdataadr(fd, ed->act_seq); // FIXME
+
+               ed->act_seq= newdataadr(fd, ed->act_seq);
 
                /* recursive link sequences, lb will be correctly initialized */
                link_recurs_seq(fd, &ed->seqbase);
@@ -4359,7 +4493,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
        link_list(fd, &(sce->markers));
        link_list(fd, &(sce->transform_spaces));
        link_list(fd, &(sce->r.layers));
-       
+
        sce->nodetree= newdataadr(fd, sce->nodetree);
        if(sce->nodetree)
                direct_link_nodetree(fd, sce->nodetree);
@@ -4381,7 +4515,6 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
                win->curswin= NULL;
                win->tweak= NULL;
 
-               win->timers.first= win->timers.last= NULL;
                win->queue.first= win->queue.last= NULL;
                win->handlers.first= win->handlers.last= NULL;
                win->modalhandlers.first= win->modalhandlers.last= NULL;
@@ -4393,12 +4526,15 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
                win->drawfail= 0;
        }
        
+       wm->timers.first= wm->timers.last= NULL;
        wm->operators.first= wm->operators.last= NULL;
-       wm->keymaps.first= wm->keymaps.last= NULL;
        wm->paintcursors.first= wm->paintcursors.last= NULL;
        wm->queue.first= wm->queue.last= NULL;
        BKE_reports_init(&wm->reports, RPT_STORE);
 
+       wm->keyconfigs.first= wm->keyconfigs.last= NULL;
+       wm->defaultconf= NULL;
+
        wm->jobs.first= wm->jobs.last= NULL;
        
        wm->windrawable= NULL;
@@ -4956,6 +5092,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
                        if (sl->spacetype==SPACE_VIEW3D) {
                                View3D *v3d= (View3D*) sl;
                                v3d->bgpic= newdataadr(fd, v3d->bgpic);
+                               v3d->flag |= V3D_INVALID_BACKBUF;
                                if(v3d->bgpic)
                                        v3d->bgpic->iuser.ok= 1;
                                if(v3d->gpd) {
@@ -5081,7 +5218,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
        }
        /* make sure we have full path in lib->filename */
        BLI_strncpy(lib->filename, lib->name, sizeof(lib->name));
-       cleanup_path(fd->filename, lib->filename);
+       cleanup_path(fd->relabase, lib->filename);
        
 //     printf("direct_link_library: name %s\n", lib->name);
 //     printf("direct_link_library: filename %s\n", lib->filename);
@@ -5180,7 +5317,7 @@ static void lib_link_group(FileData *fd, Main *main)
                                go= go->next;
                        }
                        if(add_us) group->id.us++;
-                       rem_from_group(group, NULL);    /* removes NULL entries */
+                       rem_from_group(group, NULL, NULL, NULL);        /* removes NULL entries */
                }
                group= group->id.next;
        }
@@ -5224,6 +5361,33 @@ static char *dataname(short id_code)
        
 }
 
+static BHead *read_data_into_oldnewmap(FileData *fd, BHead *bhead, char *allocname)
+{
+       bhead = blo_nextbhead(fd, bhead);
+
+       while(bhead && bhead->code==DATA) {
+               void *data;
+#if 0          
+               /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */         
+               short *sp= fd->filesdna->structs[bhead->SDNAnr];
+               char *allocname = fd->filesdna->types[ sp[0] ];
+               char *tmp= malloc(100);
+               
+               strcpy(tmp, allocname);
+               data= read_struct(fd, bhead, tmp);
+#endif
+               data= read_struct(fd, bhead, allocname);
+               
+               if (data) {
+                       oldnewmap_insert(fd->datamap, bhead->old, data, 0);
+               }
+
+               bhead = blo_nextbhead(fd, bhead);
+       }
+
+       return bhead;
+}
+
 static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID **id_r)
 {
        /* this routine reads a libblock and its direct data. Use link functions
@@ -5265,32 +5429,11 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID
                return blo_nextbhead(fd, bhead);
        }
 
-       bhead = blo_nextbhead(fd, bhead);
-
        /* need a name for the mallocN, just for debugging and sane prints on leaks */
        allocname= dataname(GS(id->name));
        
-               /* read all data */
-       
-       while(bhead && bhead->code==DATA) {
-               void *data;
-#if 0          
-               /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */         
-               short *sp= fd->filesdna->structs[bhead->SDNAnr];
-               char *allocname = fd->filesdna->types[ sp[0] ];
-               char *tmp= malloc(100);
-               
-               strcpy(tmp, allocname);
-               data= read_struct(fd, bhead, tmp);
-#endif
-               data= read_struct(fd, bhead, allocname);
-               
-               if (data) {
-                       oldnewmap_insert(fd->datamap, bhead->old, data, 0);
-               }
-
-               bhead = blo_nextbhead(fd, bhead);
-       }
+       /* read all data into fd->datamap */
+       bhead= read_data_into_oldnewmap(fd, bhead, allocname);
 
        /* init pointers direct data */
        switch( GS(id->name) ) {
@@ -5409,6 +5552,9 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)
        bfd->fileflags= fg->fileflags;
        bfd->displaymode= fg->displaymode;
        bfd->globalf= fg->globalf;
+       BLI_strncpy(bfd->filename, fg->filename, sizeof(bfd->filename));
+       if(G.fileflags & G_FILE_RECOVER)
+               BLI_strncpy(fd->relabase, fg->filename, sizeof(fd->relabase));
        
        bfd->curscreen= fg->curscreen;
        bfd->curscene= fg->curscene;
@@ -5841,7 +5987,8 @@ static void area_add_header_region(ScrArea *sa, ListBase *lb)
 static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
 {
        ARegion *ar;
-       
+       ARegion *ar_main;
+
        if(sl) {
                /* first channels for ipo action nla... */
                switch(sl->spacetype) {
@@ -5900,13 +6047,50 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                ar->regiontype= RGN_TYPE_UI;
                                ar->alignment= RGN_ALIGN_TOP;
                                break;
+                       case SPACE_SEQ:
+                               ar_main = (ARegion*)lb->first;
+                               for (; ar_main; ar_main = ar_main->next) {
+                                       if (ar_main->regiontype == RGN_TYPE_WINDOW)
+                                               break;
+                               }
+                               ar= MEM_callocN(sizeof(ARegion), "preview area for sequencer");
+                               BLI_insertlinkbefore(lb, ar_main, ar);
+                               ar->regiontype= RGN_TYPE_PREVIEW;
+                               ar->alignment= RGN_ALIGN_TOP;
+                               ar->flag |= RGN_FLAG_HIDDEN;
+                               break;
+                       case SPACE_VIEW3D:
+                               /* toolbar */
+                               ar= MEM_callocN(sizeof(ARegion), "toolbar for view3d");
+                               
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_TOOLS;
+                               ar->alignment= RGN_ALIGN_LEFT;
+                               ar->flag = RGN_FLAG_HIDDEN;
+                               
+                               /* tool properties */
+                               ar= MEM_callocN(sizeof(ARegion), "tool properties for view3d");
+                               
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_TOOL_PROPS;
+                               ar->alignment= RGN_ALIGN_BOTTOM|RGN_SPLIT_PREV;
+                               ar->flag = RGN_FLAG_HIDDEN;
+                               
+                               /* buttons/list view */
+                               ar= MEM_callocN(sizeof(ARegion), "buttons for view3d");
+                               
+                               BLI_addtail(lb, ar);
+                               ar->regiontype= RGN_TYPE_UI;
+                               ar->alignment= RGN_ALIGN_RIGHT;
+                               ar->flag = RGN_FLAG_HIDDEN;
 #if 0
                        case SPACE_BUTS:
                                /* context UI region */
                                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                                BLI_addtail(lb, ar);
-                               ar->regiontype= RGN_TYPE_CHANNELS;
-                               ar->alignment= RGN_ALIGN_TOP;
+                               ar->regiontype= RGN_TYPE_UI;
+                               ar->alignment= RGN_ALIGN_RIGHT;
+                               
                                break;
 #endif
                }
@@ -6154,14 +6338,77 @@ static void do_versions_gpencil_2_50(Main *main, bScreen *screen)
        }               
 }
 
+static void do_version_mtex_factor_2_50(MTex **mtex_array, short idtype)
+{
+       MTex *mtex;
+       float varfac, colfac;
+       int a, neg;
 
+       if(!mtex_array)
+               return;
+
+       for(a=0; a<MAX_MTEX; a++) {
+               if(mtex_array[a]) {
+                       mtex= mtex_array[a];
+
+                       neg= mtex->maptoneg;
+                       varfac= mtex->varfac;
+                       colfac= mtex->colfac;
+
+                       if(neg & MAP_DISP) mtex->dispfac= -mtex->dispfac;
+                       if(neg & MAP_NORM) mtex->norfac= -mtex->norfac;
+                       if(neg & MAP_WARP) mtex->warpfac= -mtex->warpfac;
+
+                       mtex->colspecfac= (neg & MAP_COLSPEC)? -colfac: colfac;
+                       mtex->mirrfac= (neg & MAP_COLMIR)? -colfac: colfac;
+                       mtex->alphafac= (neg & MAP_ALPHA)? -varfac: varfac;
+                       mtex->difffac= (neg & MAP_REF)? -varfac: varfac;
+                       mtex->specfac= (neg & MAP_SPEC)? -varfac: varfac;
+                       mtex->emitfac= (neg & MAP_EMIT)? -varfac: varfac;
+                       mtex->hardfac= (neg & MAP_HAR)? -varfac: varfac;
+                       mtex->raymirrfac= (neg & MAP_RAYMIRR)? -varfac: varfac;
+                       mtex->translfac= (neg & MAP_TRANSLU)? -varfac: varfac;
+                       mtex->ambfac= (neg & MAP_AMB)? -varfac: varfac;
+                       mtex->colemitfac= (neg & MAP_EMISSION_COL)? -colfac: colfac;
+                       mtex->colreflfac= (neg & MAP_REFLECTION_COL)? -colfac: colfac;
+                       mtex->coltransfac= (neg & MAP_TRANSMISSION_COL)? -colfac: colfac;
+                       mtex->densfac= (neg & MAP_DENSITY)? -varfac: varfac;
+                       mtex->scatterfac= (neg & MAP_SCATTERING)? -varfac: varfac;
+                       mtex->reflfac= (neg & MAP_REFLECTION)? -varfac: varfac;
+
+                       mtex->timefac= (neg & MAP_PA_TIME)? -varfac: varfac;
+                       mtex->lengthfac= (neg & MAP_PA_LENGTH)? -varfac: varfac;
+                       mtex->clumpfac= (neg & MAP_PA_CLUMP)? -varfac: varfac;
+                       mtex->kinkfac= (neg & MAP_PA_KINK)? -varfac: varfac;
+                       mtex->roughfac= (neg & MAP_PA_ROUGH)? -varfac: varfac;
+                       mtex->padensfac= (neg & MAP_PA_DENS)? -varfac: varfac;
+                       mtex->lifefac= (neg & MAP_PA_LIFE)? -varfac: varfac;
+                       mtex->sizefac= (neg & MAP_PA_SIZE)? -varfac: varfac;
+                       mtex->ivelfac= (neg & MAP_PA_IVEL)? -varfac: varfac;
+                       mtex->pvelfac= (neg & MAP_PA_PVEL)? -varfac: varfac;
+
+                       mtex->shadowfac= (neg & LAMAP_SHAD)? -colfac: colfac;
+
+                       mtex->zenupfac= (neg & WOMAP_ZENUP)? -colfac: colfac;
+                       mtex->zendownfac= (neg & WOMAP_ZENDOWN)? -colfac: colfac;
+                       mtex->blendfac= (neg & WOMAP_BLEND)? -varfac: varfac;
+
+                       if(idtype == ID_MA)
+                               mtex->colfac= (neg & MAP_COL)? -colfac: colfac;
+                       else if(idtype == ID_LA)
+                               mtex->colfac= (neg & LAMAP_COL)? -colfac: colfac;
+                       else if(idtype == ID_WO)
+                               mtex->colfac= (neg & WOMAP_HORIZ)? -colfac: colfac;
+               }
+       }
+}
 
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
 
        if(G.f & G_DEBUG)
-               printf("read file %s\n  Version %d sub %d\n", fd->filename, main->versionfile, main->subversionfile);
+               printf("read file %s\n  Version %d sub %d\n", fd->relabase, main->versionfile, main->subversionfile);
        
        if(main->versionfile == 100) {
                /* tex->extend and tex->imageflag have changed: */
@@ -6308,7 +6555,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
        if(main->versionfile <= 140) {
-               /* r-g-b-fac in texure */
+               /* r-g-b-fac in texture */
                Tex *tex = main->tex.first;
                while (tex) {
                        if ((tex->rfac == 0.0) &&
@@ -7536,6 +7783,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                smd->flags |= eSubsurfModifierFlag_ControlEdges;
                                        
                                        BLI_addtail(&ob->modifiers, smd);
+                                       
+                                       modifier_unique_name(&ob->modifiers, (ModifierData*)smd);
                                }
                        }
                        
@@ -8311,7 +8560,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                                
                                /* correctly initialise constinv matrix */
-                               Mat4One(ob->constinv);
+                               unit_m4(ob->constinv);
                                
                                if (ob->type == OB_ARMATURE) {
                                        if (ob->pose) {
@@ -8341,7 +8590,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                        }
                                                        
                                                        /* correctly initialise constinv matrix */
-                                                       Mat4One(pchan->constinv);
+                                                       unit_m4(pchan->constinv);
                                                }
                                        }
                                }
@@ -9004,15 +9253,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 4)){
-               Scene *sce= main->scene.first;
-               while(sce) {
-                       if(sce->frame_step==0)
-                               sce->frame_step= 1;
-                       sce= sce->id.next;
-               }
-       }
-
        if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 5)) {
                Lamp *la= main->lamp.first;
                for(; la; la= la->id.next) {
@@ -9374,7 +9614,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                /* and composit trees */
                for(sce= main->scene.first; sce; sce= sce->id.next) {
                        if(sce->nodetree && strlen(sce->nodetree->id.name)==0)
-                               strcpy(sce->nodetree->id.name, "NTComposit Nodetree");
+                               strcpy(sce->nodetree->id.name, "NTCompositing Nodetree");
 
                        /* move to cameras */
                        if(sce->r.mode & R_PANORAMA) {
@@ -9449,7 +9689,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                ToolSettings *ts;
                //PTCacheID *pid;
                //ListBase pidlist;
-               int i, a;
+               int a;
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
                        //BKE_ptcache_ids_from_object(&pidlist, ob);
@@ -9466,58 +9706,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                void *olddata = ob->data;
                                ob->data = me;
 
-                               if(me && me->id.lib==NULL && me->mr) { /* XXX - library meshes crash on loading most yoFrankie levels, the multires pointer gets invalid -  Campbell */
-                                       MultiresLevel *lvl;
-                                       ModifierData *md;
-                                       MultiresModifierData *mmd;
-                                       DerivedMesh *dm, *orig;
-
-                                       /* Load original level into the mesh */
-                                       lvl = me->mr->levels.first;
-                                       CustomData_free_layers(&me->vdata, CD_MVERT, lvl->totvert);
-                                       CustomData_free_layers(&me->edata, CD_MEDGE, lvl->totedge);
-                                       CustomData_free_layers(&me->fdata, CD_MFACE, lvl->totface);
-                                       me->totvert = lvl->totvert;
-                                       me->totedge = lvl->totedge;
-                                       me->totface = lvl->totface;
-                                       me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert);
-                                       me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, me->totedge);
-                                       me->mface = CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface);
-                                       memcpy(me->mvert, me->mr->verts, sizeof(MVert) * me->totvert);
-                                       for(i = 0; i < me->totedge; ++i) {
-                                               me->medge[i].v1 = lvl->edges[i].v[0];
-                                               me->medge[i].v2 = lvl->edges[i].v[1];
-                                       }
-                                       for(i = 0; i < me->totface; ++i) {
-                                               me->mface[i].v1 = lvl->faces[i].v[0];
-                                               me->mface[i].v2 = lvl->faces[i].v[1];
-                                               me->mface[i].v3 = lvl->faces[i].v[2];
-                                               me->mface[i].v4 = lvl->faces[i].v[3];
-                                       }
-
-                                       /* Add a multires modifier to the object */
-                                       md = ob->modifiers.first;
-                                       while(md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform)
-                                               md = md->next;                          
-                                       mmd = (MultiresModifierData*)modifier_new(eModifierType_Multires);
-                                       BLI_insertlinkbefore(&ob->modifiers, md, mmd);
-
-                                       multiresModifier_subdivide(mmd, ob, me->mr->level_count - 1, 1, 0);
-
-                                       mmd->lvl = mmd->totlvl;
-                                       orig = CDDM_from_mesh(me, NULL);
-                                       dm = multires_dm_create_from_derived(mmd, 0, orig, ob, 0, 0);
-                                       
-                                       multires_load_old(dm, me->mr);
-
-                                       MultiresDM_mark_as_modified(dm);
-                                       dm->release(dm);
-                                       orig->release(orig);
-
-                                       /* Remove the old multires */
-                                       multires_free(me->mr);
-                                       me->mr = NULL;
-                               }
+                               if(me && me->id.lib==NULL && me->mr) /* XXX - library meshes crash on loading most yoFrankie levels, the multires pointer gets invalid -  Campbell */
+                                       multires_load_old(ob, me);
 
                                ob->data = olddata;
                        }
@@ -9573,16 +9763,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        if (ma->vol.stepsize < 0.0001f) {
                                ma->vol.density = 1.0f;
                                ma->vol.emission = 0.0f;
-                               ma->vol.absorption = 1.0f;
                                ma->vol.scattering = 1.0f;
                                ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
-                               ma->vol.absorption_col[0] = ma->vol.absorption_col[1] = ma->vol.absorption_col[2] = 0.0f;
                                ma->vol.density_scale = 1.0f;
                                ma->vol.depth_cutoff = 0.01f;
                                ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
                                ma->vol.stepsize = 0.2f;
-                               ma->vol.shade_stepsize = 0.2f;
-                               ma->vol.shade_type = MA_VOL_SHADE_SINGLE;
+                               ma->vol.shade_type = MA_VOL_SHADE_SHADED;
                                ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
                                ma->vol.precache_resolution = 50;
                        }
@@ -9699,10 +9886,15 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       /* put 2.50 compatibility code here until next subversion bump */
-       {
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 4)) {
                Scene *sce;
                Object *ob;
+               Material *ma;
+               Lamp *la;
+               World *wo;
+               Tex *tex;
+               ParticleSettings *part;
+               int do_gravity = 0;
 
                for(sce = main->scene.first; sce; sce = sce->id.next)
                        if(sce->unit.scale_length == 0.0f)
@@ -9716,7 +9908,28 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        /* rotation modes were added, but old objects would now default to being 'quaternion based' */
                        ob->rotmode= ROT_MODE_EUL;
                }
+               
+               for(ma = main->mat.first; ma; ma=ma->id.next) {
+                       if(ma->vol.reflection == 0.f) {
+                               ma->vol.reflection = 1.f;
+                               ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f;
+                               ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f;
+                       }
+
+                       do_version_mtex_factor_2_50(ma->mtex, ID_MA);
+               }
+
+               for(la = main->lamp.first; la; la=la->id.next)
+                       do_version_mtex_factor_2_50(la->mtex, ID_LA);
+
+               for(wo = main->world.first; wo; wo=wo->id.next)
+                       do_version_mtex_factor_2_50(wo->mtex, ID_WO);
 
+               for(tex = main->tex.first; tex; tex=tex->id.next)
+                       if(tex->vd)
+                               if(tex->vd->extend == 0)
+                                       tex->vd->extend = TEX_CLIP;
+               
                for(sce= main->scene.first; sce; sce= sce->id.next)
                {
                        if(sce->audio.main == 0.0)
@@ -9728,6 +9941,451 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        sce->audio.doppler_factor = 1.0;
                        sce->audio.speed_of_sound = 343.3;
                }
+
+               /* Add default gravity to scenes */
+               for(sce= main->scene.first; sce; sce= sce->id.next) {
+                       if((sce->physics_settings.flag & PHYS_GLOBAL_GRAVITY) == 0
+                               && len_v3(sce->physics_settings.gravity) == 0.0f) {
+
+                               sce->physics_settings.gravity[0] = sce->physics_settings.gravity[1] = 0.0f;
+                               sce->physics_settings.gravity[2] = -9.81f;
+                               sce->physics_settings.flag = PHYS_GLOBAL_GRAVITY;
+                               do_gravity = 1;
+                       }
+               }
+
+               /* Assign proper global gravity weights for dynamics (only z-coordinate is taken into account) */
+               if(do_gravity) for(part= main->particle.first; part; part= part->id.next)
+                       part->effector_weights->global_gravity = part->acc[2]/-9.81f;
+
+               for(ob = main->object.first; ob; ob = ob->id.next) {
+                       ModifierData *md;
+
+                       if(do_gravity) {
+                               for(md= ob->modifiers.first; md; md= md->next) {
+                                       ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
+                                       if(clmd)
+                                               clmd->sim_parms->effector_weights->global_gravity = clmd->sim_parms->gravity[2]/-9.81;
+                               }
+
+                               if(ob->soft)
+                                       ob->soft->effector_weights->global_gravity = ob->soft->grav/9.81;
+                       }
+
+                       /* Normal wind shape is plane */
+                       if(ob->pd) {
+                               if(ob->pd->forcefield == PFIELD_WIND)
+                                       ob->pd->shape = PFIELD_SHAPE_PLANE;
+                               
+                               if(ob->pd->flag & PFIELD_PLANAR)
+                                       ob->pd->shape = PFIELD_SHAPE_PLANE;
+                               else if(ob->pd->flag & PFIELD_SURFACE)
+                                       ob->pd->shape = PFIELD_SHAPE_SURFACE;
+                       }
+               }
+       }
+
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 6)) {
+               Object *ob;
+               Lamp *la;
+               
+               /* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialisation */
+               for (ob= main->object.first; ob; ob= ob->id.next) {
+                       /* new variables for all objects */
+                       ob->quat[0]= 1.0f;
+                       ob->rotAxis[1]= 1.0f;
+                       
+                       /* bones */
+                       if (ob->pose) {
+                               bPoseChannel *pchan;
+                               
+                               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
+                                       /* just need to initalise rotation axis properly... */
+                                       pchan->rotAxis[1]= 1.0f;
+                               }
+                       }
+               }
+
+               for(la = main->lamp.first; la; la=la->id.next)
+                       la->compressthresh= 0.05f;
+       }
+
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 7)) {
+               Mesh *me;
+               Nurb *nu;
+               Lattice *lt;
+               Curve *cu;
+               Key *key;
+               float *data;
+               int a, tot;
+
+               /* shape keys are no longer applied to the mesh itself, but rather
+                  to the derivedmesh/displist, so here we ensure that the basis
+                  shape key is always set in the mesh coordinates. */
+
+               for(me= main->mesh.first; me; me= me->id.next) {
+                       if((key = newlibadr(fd, lib, me->key)) && key->refkey) {
+                               data= key->refkey->data;
+                               tot= MIN2(me->totvert, key->refkey->totelem);
+
+                               for(a=0; a<tot; a++, data+=3)
+                                       VECCOPY(me->mvert[a].co, data)
+                       }
+               }
+
+               for(lt= main->latt.first; lt; lt= lt->id.next) {
+                       if((key = newlibadr(fd, lib, lt->key)) && key->refkey) {
+                               data= key->refkey->data;
+                               tot= MIN2(lt->pntsu*lt->pntsv*lt->pntsw, key->refkey->totelem);
+
+                               for(a=0; a<tot; a++, data+=3)
+                                       VECCOPY(lt->def[a].vec, data)
+                       }
+               }
+
+               for(cu= main->curve.first; cu; cu= cu->id.next) {
+                       if((key = newlibadr(fd, lib, cu->key)) && key->refkey) {
+                               data= key->refkey->data;
+
+                               for(nu=cu->nurb.first; nu; nu=nu->next) {
+                                       if(nu->bezt) {
+                                               BezTriple *bezt = nu->bezt;
+
+                                               for(a=0; a<nu->pntsu; a++, bezt++) {
+                                                       VECCOPY(bezt->vec[0], data); data+=3;
+                                                       VECCOPY(bezt->vec[1], data); data+=3;
+                                                       VECCOPY(bezt->vec[2], data); data+=3;
+                                                       bezt->alfa= *data; data++;
+                                               }
+                                       }
+                                       else if(nu->bp) {
+                                               BPoint *bp = nu->bp;
+
+                                               for(a=0; a<nu->pntsu*nu->pntsv; a++, bp++) {
+                                                       VECCOPY(bp->vec, data); data+=3;
+                                                       bp->alfa= *data; data++;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 8))
+       {
+               {
+                       Scene *sce= main->scene.first;
+                       while(sce) {
+                               Sequence *seq;
+                               
+                               if(sce->r.frame_step==0)
+                                       sce->r.frame_step= 1;
+                               
+                               if(sce->ed && sce->ed->seqbasep)
+                               {
+                                       seq=sce->ed->seqbasep->first;
+                                       while(seq) {
+                                               seqUniqueName(sce->ed->seqbasep, seq);
+                                               seq=seq->next;
+                                       }
+                               }
+                               
+                               sce= sce->id.next;
+                       }
+               }
+               {
+                       /* ensure all nodes have unique names */
+                       bNodeTree *ntree= main->nodetree.first;
+                       while(ntree) {
+                               bNode *node=ntree->nodes.first;
+                               
+                               while(node) {
+                                       nodeUniqueName(ntree, node);
+                                       node= node->next;
+                               }
+                               
+                               ntree= ntree->id.next;
+                       }
+               }
+               {
+                       Object *ob=main->object.first;
+                       while (ob) {
+                               /* shaded mode disabled for now */
+                               if (ob->dt == OB_SHADED) ob->dt = OB_TEXTURE;
+                               ob=ob->id.next;
+                       }
+               }
+               
+               {
+                       bScreen *screen;
+                       ScrArea *sa;
+                       SpaceLink *sl;
+                       
+                       for(screen= main->screen.first; screen; screen= screen->id.next) {
+                               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                                       for(sl= sa->spacedata.first; sl; sl= sl->next) {
+                                               if(sl->spacetype==SPACE_VIEW3D) {
+                                                       View3D *v3d = (View3D *)sl;
+                                                       if (v3d->drawtype == OB_SHADED) v3d->drawtype = OB_SOLID;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               
+               /* only convert old 2.50 files with color management */
+               if (main->versionfile == 250) {
+                       Scene *sce=main->scene.first;
+                       Material *ma=main->mat.first;
+                       World *wo=main->world.first;
+                       int convert=0;
+                       
+                       /* convert to new color management system:
+                        while previously colors were stored as srgb, 
+                        now they are stored as linear internally, 
+                        with screen gamma correction in certain places in the UI. */
+
+                       /* don't know what scene is active, so we'll convert if any scene has it enabled... */
+                       while (sce) {
+                               if(sce->r.color_mgt_flag & R_COLOR_MANAGEMENT)
+                                       convert=1;
+                               sce=sce->id.next;
+                       }
+                       
+                       if (convert) {
+                               while(ma) {
+                                       srgb_to_linearrgb_v3_v3(&ma->r, &ma->r);
+                                       srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr);
+                                       srgb_to_linearrgb_v3_v3(&ma->mirr, &ma->mirr);
+                                       srgb_to_linearrgb_v3_v3(ma->sss_col, ma->sss_col);
+                                       ma=ma->id.next;
+                               }
+                               
+                               while(wo) {
+                                       srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr);
+                                       srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr);
+                                       srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr);
+                                       wo=wo->id.next;
+                               }
+                       }
+               }
+               /* clear hanging 'temp' screens from older 2.5 files*/
+               if (main->versionfile == 250) {
+                       bScreen *screen, *nextscreen;
+                       wmWindowManager *wm;
+                       wmWindow *win, *nextwin;
+
+                       for(screen= main->screen.first; screen; screen= nextscreen) {
+                               nextscreen= screen->id.next;
+
+                               if (screen->full == SCREENTEMP) {
+                                       /* remove corresponding windows */
+                                       for(wm= main->wm.first; wm; wm=wm->id.next) {
+                                               for(win= wm->windows.first; win; win=nextwin) {
+                                                       nextwin= win->next;
+
+                                                       if(newlibadr(fd, wm->id.lib, win->screen) == screen)
+                                                               BLI_freelinkN(&wm->windows, win);
+                                               }
+                                       }
+
+                                       /* remove screen itself */
+                                       free_libblock(&main->screen, screen);
+                               }
+                       }
+               }
+       }
+       
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 9))
+       {
+               Scene *sce;
+               Mesh *me;
+               Object *ob;
+
+               for(sce=main->scene.first; sce; sce=sce->id.next)
+                       if(!sce->toolsettings->particle.selectmode)
+                               sce->toolsettings->particle.selectmode= SCE_SELECT_PATH;
+
+               if (main->versionfile == 250 && main->subversionfile > 1) {
+                       for(me=main->mesh.first; me; me=me->id.next)
+                               multires_load_old_250(me);
+
+                       for(ob=main->object.first; ob; ob=ob->id.next) {
+                               MultiresModifierData *mmd = (MultiresModifierData *)modifiers_findByType(ob, eModifierType_Multires);
+
+                               if(mmd) {
+                                       mmd->totlvl--;
+                                       mmd->lvl--;
+                                       mmd->sculptlvl= mmd->lvl;
+                                       mmd->renderlvl= mmd->lvl;
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 10))
+       {
+               Object *ob;
+
+               /* properly initialise hair clothsim data on old files */
+               for(ob = main->object.first; ob; ob = ob->id.next) {
+                       ModifierData *md;
+                       for(md= ob->modifiers.first; md; md= md->next) {
+                               if (md->type == eModifierType_Cloth) {
+                                       ClothModifierData *clmd = (ClothModifierData *)md;
+                                       if (clmd->sim_parms->velocity_smooth < 0.01f)
+                                               clmd->sim_parms->velocity_smooth = 0.f;
+                               }
+                       }
+               }
+       }
+
+       /* fix bad area setup in subversion 10 */
+       if (main->versionfile == 250 && main->subversionfile == 10)
+       {
+               /* fix for new view type in sequencer */
+               bScreen *screen;
+               ScrArea *sa;
+               SpaceLink *sl;
+
+
+               /* remove all preview window in wrong spaces */
+               for(screen= main->screen.first; screen; screen= screen->id.next) {
+                       for(sa= screen->areabase.first; sa; sa= sa->next) {
+                               for(sl= sa->spacedata.first; sl; sl= sl->next) {
+                                       if(sl->spacetype!=SPACE_SEQ) {
+                                               ARegion *ar;
+                                               ListBase *regionbase;
+
+                                               if (sl == sa->spacedata.first) {
+                                                       regionbase = &sa->regionbase;
+                                               } else {
+                                                       regionbase = &sl->regionbase;
+                                               }
+
+
+                                               for( ar = regionbase->first; ar; ar = ar->next) {
+                                                       if (ar->regiontype == RGN_TYPE_PREVIEW)
+                                                               break;
+                                               }
+
+                                               if (ar) {
+                                                       SpaceType *st= BKE_spacetype_from_id(SPACE_SEQ);
+                                                       BKE_area_region_free(st, ar);
+                                                       BLI_freelinkN(regionbase, ar);
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 11))
+       {
+               {
+                       /* fix for new view type in sequencer */
+                       bScreen *screen;
+                       ScrArea *sa;
+                       SpaceLink *sl;
+
+
+                       for(screen= main->screen.first; screen; screen= screen->id.next) {
+                               for(sa= screen->areabase.first; sa; sa= sa->next) {
+                                       for(sl= sa->spacedata.first; sl; sl= sl->next) {
+                                               if(sl->spacetype==SPACE_SEQ) {
+                                                       ARegion *ar;
+                                                       ARegion *ar_main;
+                                                       ListBase *regionbase;
+                                                       SpaceSeq *sseq = (SpaceSeq *)sl;
+
+                                                       if (sl == sa->spacedata.first) {
+                                                               regionbase = &sa->regionbase;
+                                                       } else {
+                                                               regionbase = &sl->regionbase;
+                                                       }
+
+                                                       if (sseq->view == 0) sseq->view = SEQ_VIEW_SEQUENCE;
+                                                       if (sseq->mainb == 0) sseq->mainb = SEQ_DRAW_IMG_IMBUF;
+
+                                                       ar_main = (ARegion*)regionbase->first;
+                                                       for (; ar_main; ar_main = ar_main->next) {
+                                                               if (ar_main->regiontype == RGN_TYPE_WINDOW)
+                                                                       break;
+                                                       }
+                                                       ar= MEM_callocN(sizeof(ARegion), "preview area for sequencer");
+                                                       BLI_insertlinkbefore(regionbase, ar_main, ar);
+                                                       ar->regiontype= RGN_TYPE_PREVIEW;
+                                                       ar->alignment= RGN_ALIGN_TOP;
+                                                       ar->flag |= RGN_FLAG_HIDDEN;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /* put 2.50 compatibility code here until next subversion bump */
+
+       if (1) {
+               Scene *sce;
+               Object *ob;
+               
+               /* game engine changes */
+               for(sce = main->scene.first; sce; sce = sce->id.next) {
+                       sce->gm.eyeseparation = 0.10;
+               }
+               
+               /* anim viz changes */
+               for (ob= main->object.first; ob; ob= ob->id.next) {
+                       /* initialise object defaults */
+                       animviz_settings_init(&ob->avs);
+                       
+                       /* if armature, copy settings for pose from armature data */
+                       if (ob->pose && ob->data) {
+                               bArmature *arm= newlibadr(fd, lib, ob->data);
+                               bAnimVizSettings *avs= &ob->pose->avs;
+                               
+                               /* ghosting settings ---------------- */
+                                       /* ranges */
+                               avs->ghost_bc= avs->ghost_ac= arm->ghostep;
+                               
+                               avs->ghost_sf= arm->ghostsf;
+                               avs->ghost_ef= arm->ghostef;
+                                       
+                                       /* type */
+                               avs->ghost_type= arm->ghosttype;
+                                       
+                                       /* stepsize */
+                               avs->ghost_step= arm->ghostsize;
+                               
+                               /* path settings --------------------- */
+                                       /* ranges */
+                               avs->path_bc= arm->pathbc;
+                               avs->path_ac= arm->pathac;
+                               
+                               avs->path_sf= arm->pathsf;
+                               avs->path_ef= arm->pathef;
+                               
+                                       /* flags */
+                               if (arm->pathflag & ARM_PATH_FNUMS)
+                                       avs->path_viewflag |= MOTIONPATH_VIEW_FNUMS;
+                               if (arm->pathflag & ARM_PATH_KFRAS)
+                                       avs->path_viewflag |= MOTIONPATH_VIEW_KFRAS;
+                               if (arm->pathflag & ARM_PATH_KFNOS)
+                                       avs->path_viewflag |= MOTIONPATH_VIEW_KFNOS;
+                                       
+                                       /* bake flags */
+                               if (arm->pathflag & ARM_PATH_HEADS)
+                                       avs->path_bakeflag |= MOTIONPATH_BAKE_HEADS;
+                                       
+                                       /* type */
+                               if (arm->pathflag & ARM_PATH_ACFRA)
+                                       avs->path_type = MOTIONPATH_TYPE_ACFRA;
+                               
+                                       /* stepsize */
+                               avs->path_step= arm->pathsize;
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -9773,23 +10431,39 @@ static void lib_link_all(FileData *fd, Main *main)
 
 static BHead *read_userdef(BlendFileData *bfd, FileData *fd, BHead *bhead)
 {
-       Link *link;
+       UserDef *user;
+       wmKeyMap *keymap;
+       wmKeyMapItem *kmi;
 
-       bfd->user= read_struct(fd, bhead, "user def");
-       bfd->user->themes.first= bfd->user->themes.last= NULL;
-       // XXX
-       bfd->user->uifonts.first= bfd->user->uifonts.last= NULL;
-       bfd->user->uistyles.first= bfd->user->uistyles.last= NULL;
+       bfd->user= user= read_struct(fd, bhead, "user def");
 
-       bhead = blo_nextbhead(fd, bhead);
+       /* read all data into fd->datamap */
+       bhead= read_data_into_oldnewmap(fd, bhead, "user def");
 
-               /* read all attached data */
-       while(bhead && bhead->code==DATA) {
-               link= read_struct(fd, bhead, "user def data");
-               BLI_addtail(&bfd->user->themes, link);
-               bhead = blo_nextbhead(fd, bhead);
+       link_list(fd, &user->themes);
+       link_list(fd, &user->keymaps);
+
+       for(keymap=user->keymaps.first; keymap; keymap=keymap->next) {
+               keymap->modal_items= NULL;
+               keymap->poll= NULL;
+
+               link_list(fd, &keymap->items);
+               for(kmi=keymap->items.first; kmi; kmi=kmi->next) {
+                       kmi->properties= newdataadr(fd, kmi->properties);
+                       if(kmi->properties)
+                               IDP_DirectLinkProperty(kmi->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+                       kmi->ptr= NULL;
+               }
        }
 
+       // XXX
+       user->uifonts.first= user->uifonts.last= NULL;
+       user->uistyles.first= user->uistyles.last= NULL;
+
+       /* free fd->datamap again */
+       oldnewmap_free_unused(fd->datamap);
+       oldnewmap_clear(fd->datamap);
+
        return bhead;
 }
 
@@ -9826,14 +10500,25 @@ BlendFileData *blo_read_file_internal(FileData *fd, char *file)
                        break;
 
                case ID_LI:
-                       bhead = read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
+                       /* skip library datablocks in undo, this works together with
+                          BLO_read_from_memfile, where the old main->library is restored
+                          overwriting  the libraries from the memory file. previously
+                          it did not save ID_LI/ID_ID blocks in this case, but they are
+                          needed to make quit.blend recover them correctly. */
+                       if(fd->memfile)
+                               bhead= blo_nextbhead(fd, bhead);
+                       else
+                               bhead= read_libblock(fd, bfd->main, bhead, LIB_LOCAL, NULL);
                        break;
                case ID_ID:
+                       /* same as above */
+                       if(fd->memfile)
+                               bhead= blo_nextbhead(fd, bhead);
+                       else
                                /* always adds to the most recently loaded
                                 * ID_LI block, see direct_link_library.
-                                * this is part of the file format definition.
-                                */
-                       bhead = read_libblock(fd, fd->mainlist.last, bhead, LIB_READ+LIB_EXTERN, NULL);
+                                * this is part of the file format definition. */
+                               bhead = read_libblock(fd, fd->mainlist.last, bhead, LIB_READ+LIB_EXTERN, NULL);
                        break;
                        
                        /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
@@ -9855,7 +10540,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, char *file)
 
        lib_link_all(fd, bfd->main);
        lib_verify_nodetree(bfd->main, 1);
-       fix_relpaths_library(fd->filename, bfd->main); /* make all relative paths, relative to the open blend file */
+       fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */
        
        link_global(fd, bfd);   /* as last */
        
@@ -9903,6 +10588,10 @@ static void sort_bhead_old_map(FileData *fd)
 
 static BHead *find_previous_lib(FileData *fd, BHead *bhead)
 {
+       /* skip library datablocks in undo, see comment in read_libblock */
+       if(fd->memfile)
+               return NULL;
+
        for (; bhead; bhead= blo_prevbhead(fd, bhead))
                if (bhead->code==ID_LI)
                        break;
@@ -9974,7 +10663,7 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
 
                        if(bheadlib) {
                                Library *lib= read_struct(fd, bheadlib, "Library");
-                               Main *ptr= blo_find_main(fd, &fd->mainlist, lib->name, fd->filename);
+                               Main *ptr= blo_find_main(fd, &fd->mainlist, lib->name, fd->relabase);
 
                                id= is_yet_read(fd, ptr, bhead);
 
@@ -10037,15 +10726,56 @@ static void expand_constraint_channels(FileData *fd, Main *mainvar, ListBase *ch
        }
 }
 
-// XXX depreceated - old animation system
+static void expand_fmodifiers(FileData *fd, Main *mainvar, ListBase *list)
+{
+       FModifier *fcm;
+       
+       for (fcm= list->first; fcm; fcm= fcm->next) {
+               /* library data for specific F-Modifier types */
+               switch (fcm->type) {
+                       case FMODIFIER_TYPE_PYTHON:
+                       {
+                               FMod_Python *data= (FMod_Python *)fcm->data;
+                               
+                               expand_doit(fd, mainvar, data->script);
+                       }
+                               break;
+               }
+       }
+}
+
+static void expand_fcurves(FileData *fd, Main *mainvar, ListBase *list)
+{
+       FCurve *fcu;
+       
+       for (fcu= list->first; fcu; fcu= fcu->next) {
+               /* Driver targets if there is a driver */
+               if (fcu->driver) {
+                       ChannelDriver *driver= fcu->driver;
+                       DriverTarget *dtar;
+                       
+                       for (dtar= driver->targets.first; dtar; dtar= dtar->next)
+                               expand_doit(fd, mainvar, dtar->id);
+               }
+               
+               /* F-Curve Modifiers */
+               expand_fmodifiers(fd, mainvar, &fcu->modifiers);
+       }
+}
+
 static void expand_action(FileData *fd, Main *mainvar, bAction *act)
 {
        bActionChannel *chan;
        
+       // XXX depreceated - old animation system --------------
        for (chan=act->chanbase.first; chan; chan=chan->next) {
                expand_doit(fd, mainvar, chan->ipo);
                expand_constraint_channels(fd, mainvar, &chan->constraintChannels);
        }
+       // ---------------------------------------------------
+       
+       /* F-Curves in Action */
+       expand_fcurves(fd, mainvar, &act->curves);
 }
 
 static void expand_keyingsets(FileData *fd, Main *mainvar, ListBase *list)
@@ -10069,6 +10799,12 @@ static void expand_animdata_nlastrips(FileData *fd, Main *mainvar, ListBase *lis
                /* check child strips */
                expand_animdata_nlastrips(fd, mainvar, &strip->strips);
                
+               /* check F-Curves */
+               expand_fcurves(fd, mainvar, &strip->fcurves);
+               
+               /* check F-Modifiers */
+               expand_fmodifiers(fd, mainvar, &strip->modifiers);
+               
                /* relink referenced action */
                expand_doit(fd, mainvar, strip->act);
        }
@@ -10076,7 +10812,6 @@ static void expand_animdata_nlastrips(FileData *fd, Main *mainvar, ListBase *lis
 
 static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
 {
-       FCurve *fcd;
        NlaTrack *nlt;
        
        /* own action */
@@ -10084,13 +10819,7 @@ static void expand_animdata(FileData *fd, Main *mainvar, AnimData *adt)
        expand_doit(fd, mainvar, adt->tmpact);
        
        /* drivers - assume that these F-Curves have driver data to be in this list... */
-       for (fcd= adt->drivers.first; fcd; fcd= fcd->next) {
-               ChannelDriver *driver= fcd->driver;
-               DriverTarget *dtar;
-               
-               for (dtar= driver->targets.first; dtar; dtar= dtar->next)
-                       expand_doit(fd, mainvar, dtar->id);
-       }
+       expand_fcurves(fd, mainvar, &adt->drivers);
        
        /* nla-data - referenced actions */
        for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) 
@@ -10131,6 +10860,9 @@ static void expand_nodetree(FileData *fd, Main *mainvar, bNodeTree *ntree)
        
        if(ntree->adt)
                expand_animdata(fd, mainvar, ntree->adt);
+               
+       if(ntree->gpd)
+               expand_doit(fd, mainvar, ntree->gpd);
        
        for(node= ntree->nodes.first; node; node= node->next)
                if(node->id && node->type!=CMP_NODE_R_LAYERS)
@@ -10410,6 +11142,18 @@ static void expand_constraints(FileData *fd, Main *mainvar, ListBase *lb)
                                expand_doit(fd, mainvar, data->target);
                        }
                        break;
+               case CONSTRAINT_TYPE_DAMPTRACK:
+                       {
+                               bDampTrackConstraint *data = (bDampTrackConstraint*)curcon->data;
+                               expand_doit(fd, mainvar, data->tar);
+                       }
+                       break;
+               case CONSTRAINT_TYPE_SPLINEIK:
+                       {
+                               bSplineIKConstraint *data = (bSplineIKConstraint*)curcon->data;
+                               expand_doit(fd, mainvar, data->tar);
+                       }
+                       break;
                default:
                        break;
                }
@@ -10670,6 +11414,28 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
                
        if(sce->gpd)
                expand_doit(fd, mainvar, sce->gpd);
+
+       if(sce->ed) {
+               Sequence *seq;
+
+               SEQ_BEGIN(sce->ed, seq) {
+                       if(seq->scene) expand_doit(fd, mainvar, seq->scene);
+                       if(seq->sound) expand_doit(fd, mainvar, seq->sound);
+               }
+               SEQ_END
+       }
+
+#ifdef DURIAN_CAMERA_SWITCH
+       {
+               TimeMarker *marker;
+
+               for(marker= sce->markers.first; marker; marker= marker->next) {
+                       if(marker->camera) {
+                               expand_doit(fd, mainvar, marker->camera);
+                       }
+               }
+       }
+#endif
 }
 
 static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
@@ -11232,7 +11998,7 @@ BlendFileData *blo_read_blendafterruntime(int file, char *name, int actualsize,
        fd->read = fd_read_from_file;
 
        /* needed for library_append and read_libraries */
-       BLI_strncpy(fd->filename, name, sizeof(fd->filename));
+       BLI_strncpy(fd->relabase, name, sizeof(fd->relabase));
 
        fd = blo_decode_and_check(fd, reports);
        if (!fd)