Merge branch 'master' into blender2.8
authorBastien Montagne <montagne29@wanadoo.fr>
Fri, 17 Mar 2017 10:00:41 +0000 (11:00 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 17 Mar 2017 10:00:41 +0000 (11:00 +0100)
Conflicts:
source/blender/blenloader/intern/writefile.c

1  2 
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/object/object_add.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_init_exit.c

index 2ffa2f9f64d250e59da3a865f90f50f94239ab0e,57be237be6fc7cf25b682009a17b0f7428f7470f..f21003b66aca1a4e76bbdd170eda0ce02f525d30
@@@ -2312,187 -2286,153 +2286,170 @@@ static void write_mesh(WriteData *wd, M
                }
        }
  
-       mywrite_flush(wd);
+       if (vlayers && vlayers != vlayers_buff) {
+               MEM_freeN(vlayers);
+       }
+       if (elayers && elayers != elayers_buff) {
+               MEM_freeN(elayers);
+       }
+       if (flayers && flayers != flayers_buff) {
+               MEM_freeN(flayers);
+       }
+       if (llayers && llayers != llayers_buff) {
+               MEM_freeN(llayers);
+       }
+       if (players && players != players_buff) {
+               MEM_freeN(players);
+       }
  }
  
- static void write_lattices(WriteData *wd, ListBase *idbase)
+ static void write_lattice(WriteData *wd, Lattice *lt)
  {
-       for (Lattice *lt = idbase->first; lt; lt = lt->id.next) {
-               if (lt->id.us > 0 || wd->current) {
-                       /* write LibData */
-                       writestruct(wd, ID_LT, Lattice, 1, lt);
-                       write_iddata(wd, &lt->id);
+       if (lt->id.us > 0 || wd->current) {
+               /* write LibData */
+               writestruct(wd, ID_LT, Lattice, 1, lt);
+               write_iddata(wd, &lt->id);
  
-                       /* write animdata */
-                       if (lt->adt) {
-                               write_animdata(wd, lt->adt);
-                       }
+               /* write animdata */
+               if (lt->adt) {
+                       write_animdata(wd, lt->adt);
+               }
  
-                       /* direct data */
-                       writestruct(wd, DATA, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
+               /* direct data */
+               writestruct(wd, DATA, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
  
-                       write_dverts(wd, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
-               }
+               write_dverts(wd, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
        }
-       mywrite_flush(wd);
  }
  
- static void write_images(WriteData *wd, ListBase *idbase)
+ static void write_image(WriteData *wd, Image *ima)
  {
-       for (Image *ima = idbase->first; ima; ima = ima->id.next) {
-               if (ima->id.us > 0 || wd->current) {
-                       ImagePackedFile *imapf;
+       if (ima->id.us > 0 || wd->current) {
+               ImagePackedFile *imapf;
  
-                       /* Some trickery to keep forward compatibility of packed images. */
-                       BLI_assert(ima->packedfile == NULL);
-                       if (ima->packedfiles.first != NULL) {
-                               imapf = ima->packedfiles.first;
-                               ima->packedfile = imapf->packedfile;
-                       }
+               /* Some trickery to keep forward compatibility of packed images. */
+               BLI_assert(ima->packedfile == NULL);
+               if (ima->packedfiles.first != NULL) {
+                       imapf = ima->packedfiles.first;
+                       ima->packedfile = imapf->packedfile;
+               }
  
-                       /* write LibData */
-                       writestruct(wd, ID_IM, Image, 1, ima);
-                       write_iddata(wd, &ima->id);
+               /* write LibData */
+               writestruct(wd, ID_IM, Image, 1, ima);
+               write_iddata(wd, &ima->id);
  
-                       for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
-                               writestruct(wd, DATA, ImagePackedFile, 1, imapf);
-                               if (imapf->packedfile) {
-                                       PackedFile *pf = imapf->packedfile;
-                                       writestruct(wd, DATA, PackedFile, 1, pf);
-                                       writedata(wd, DATA, pf->size, pf->data);
-                               }
+               for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) {
+                       writestruct(wd, DATA, ImagePackedFile, 1, imapf);
+                       if (imapf->packedfile) {
+                               PackedFile *pf = imapf->packedfile;
+                               writestruct(wd, DATA, PackedFile, 1, pf);
+                               writedata(wd, DATA, pf->size, pf->data);
                        }
+               }
  
-                       write_previews(wd, ima->preview);
+               write_previews(wd, ima->preview);
  
-                       for (ImageView *iv = ima->views.first; iv; iv = iv->next) {
-                               writestruct(wd, DATA, ImageView, 1, iv);
-                       }
-                       writestruct(wd, DATA, Stereo3dFormat, 1, ima->stereo3d_format);
-                       ima->packedfile = NULL;
+               for (ImageView *iv = ima->views.first; iv; iv = iv->next) {
+                       writestruct(wd, DATA, ImageView, 1, iv);
                }
-       }
+               writestruct(wd, DATA, Stereo3dFormat, 1, ima->stereo3d_format);
  
-       mywrite_flush(wd);
+               ima->packedfile = NULL;
+       }
  }
  
- static void write_textures(WriteData *wd, ListBase *idbase)
+ static void write_texture(WriteData *wd, Tex *tex)
  {
-       for (Tex *tex = idbase->first; tex; tex = tex->id.next) {
-               if (tex->id.us > 0 || wd->current) {
-                       /* write LibData */
-                       writestruct(wd, ID_TE, Tex, 1, tex);
-                       write_iddata(wd, &tex->id);
+       if (tex->id.us > 0 || wd->current) {
+               /* write LibData */
+               writestruct(wd, ID_TE, Tex, 1, tex);
+               write_iddata(wd, &tex->id);
  
-                       if (tex->adt) {
-                               write_animdata(wd, tex->adt);
-                       }
+               if (tex->adt) {
+                       write_animdata(wd, tex->adt);
+               }
  
-                       /* direct data */
-                       if (tex->coba) {
-                               writestruct(wd, DATA, ColorBand, 1, tex->coba);
-                       }
-                       if (tex->type == TEX_ENVMAP && tex->env) {
-                               writestruct(wd, DATA, EnvMap, 1, tex->env);
-                       }
-                       if (tex->type == TEX_POINTDENSITY && tex->pd) {
-                               writestruct(wd, DATA, PointDensity, 1, tex->pd);
-                               if (tex->pd->coba) {
-                                       writestruct(wd, DATA, ColorBand, 1, tex->pd->coba);
-                               }
-                               if (tex->pd->falloff_curve) {
-                                       write_curvemapping(wd, tex->pd->falloff_curve);
-                               }
-                       }
-                       if (tex->type == TEX_VOXELDATA) {
-                               writestruct(wd, DATA, VoxelData, 1, tex->vd);
-                       }
-                       if (tex->type == TEX_OCEAN && tex->ot) {
-                               writestruct(wd, DATA, OceanTex, 1, tex->ot);
+               /* direct data */
+               if (tex->coba) {
+                       writestruct(wd, DATA, ColorBand, 1, tex->coba);
+               }
+               if (tex->type == TEX_ENVMAP && tex->env) {
+                       writestruct(wd, DATA, EnvMap, 1, tex->env);
+               }
+               if (tex->type == TEX_POINTDENSITY && tex->pd) {
+                       writestruct(wd, DATA, PointDensity, 1, tex->pd);
+                       if (tex->pd->coba) {
+                               writestruct(wd, DATA, ColorBand, 1, tex->pd->coba);
                        }
-                       /* nodetree is integral part of texture, no libdata */
-                       if (tex->nodetree) {
-                               writestruct(wd, DATA, bNodeTree, 1, tex->nodetree);
-                               write_nodetree(wd, tex->nodetree);
+                       if (tex->pd->falloff_curve) {
+                               write_curvemapping(wd, tex->pd->falloff_curve);
                        }
+               }
+               if (tex->type == TEX_VOXELDATA) {
+                       writestruct(wd, DATA, VoxelData, 1, tex->vd);
+               }
+               if (tex->type == TEX_OCEAN && tex->ot) {
+                       writestruct(wd, DATA, OceanTex, 1, tex->ot);
+               }
  
-                       write_previews(wd, tex->preview);
+               /* nodetree is integral part of texture, no libdata */
+               if (tex->nodetree) {
+                       writestruct(wd, DATA, bNodeTree, 1, tex->nodetree);
+                       write_nodetree_nolib(wd, tex->nodetree);
                }
-       }
  
-       mywrite_flush(wd);
+               write_previews(wd, tex->preview);
+       }
  }
  
- static void write_materials(WriteData *wd, ListBase *idbase)
 +static void write_material_engines_settings(WriteData *wd, ListBase *lb)
 +{
 +      for (MaterialEngineSettings *res = lb->first; res; res = res->next) {
 +              writestruct(wd, DATA, MaterialEngineSettings, 1, res);
 +
 +              if (STREQ(res->name, RE_engine_id_BLENDER_CLAY)) {
 +                      writestruct(wd, DATA, MaterialEngineSettingsClay, 1, res->data);
 +              }
 +              else {
 +                      /* No engine matched */
 +                      /* error: don't know how to write this file */
 +              }
 +      }
 +}
 +
+ static void write_material(WriteData *wd, Material *ma)
  {
-       for (Material *ma = idbase->first; ma; ma = ma->id.next) {
-               if (ma->id.us > 0 || wd->current) {
-                       /* write LibData */
-                       writestruct(wd, ID_MA, Material, 1, ma);
-                       write_iddata(wd, &ma->id);
+       if (ma->id.us > 0 || wd->current) {
+               /* write LibData */
+               writestruct(wd, ID_MA, Material, 1, ma);
+               write_iddata(wd, &ma->id);
  
-                       if (ma->adt) {
-                               write_animdata(wd, ma->adt);
-                       }
+               if (ma->adt) {
+                       write_animdata(wd, ma->adt);
+               }
  
-                       for (int a = 0; a < MAX_MTEX; a++) {
-                               if (ma->mtex[a]) {
-                                       writestruct(wd, DATA, MTex, 1, ma->mtex[a]);
-                               }
+               for (int a = 0; a < MAX_MTEX; a++) {
+                       if (ma->mtex[a]) {
+                               writestruct(wd, DATA, MTex, 1, ma->mtex[a]);
                        }
+               }
  
-                       if (ma->ramp_col) {
-                               writestruct(wd, DATA, ColorBand, 1, ma->ramp_col);
-                       }
-                       if (ma->ramp_spec) {
-                               writestruct(wd, DATA, ColorBand, 1, ma->ramp_spec);
-                       }
+               if (ma->ramp_col) {
+                       writestruct(wd, DATA, ColorBand, 1, ma->ramp_col);
+               }
+               if (ma->ramp_spec) {
+                       writestruct(wd, DATA, ColorBand, 1, ma->ramp_spec);
+               }
  
-                       /* nodetree is integral part of material, no libdata */
-                       if (ma->nodetree) {
-                               writestruct(wd, DATA, bNodeTree, 1, ma->nodetree);
-                               write_nodetree(wd, ma->nodetree);
-                       }
+               /* nodetree is integral part of material, no libdata */
+               if (ma->nodetree) {
+                       writestruct(wd, DATA, bNodeTree, 1, ma->nodetree);
+                       write_nodetree_nolib(wd, ma->nodetree);
+               }
  
-                       write_previews(wd, ma->preview);
+               write_previews(wd, ma->preview);
 +
-                       write_material_engines_settings(wd, &ma->engines_settings);
-               }
++              write_material_engines_settings(wd, &ma->engines_settings);
        }
  }
  
@@@ -2602,343 -2536,253 +2553,328 @@@ static void write_paint(WriteData *wd, 
        }
  }
  
- static void write_scenes(WriteData *wd, ListBase *scebase)
 +static void write_scene_collection(WriteData *wd, SceneCollection *sc)
 +{
 +      writestruct(wd, DATA, SceneCollection, 1, sc);
 +
 +      writelist(wd, DATA, LinkData, &sc->objects);
 +      writelist(wd, DATA, LinkData, &sc->filter_objects);
 +
 +      for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
 +              write_scene_collection(wd, nsc);
 +      }
 +}
 +
 +static void write_collection_engine_settings(WriteData *wd, ListBase *lb)
 +{
 +      for (CollectionEngineSettings *ces = lb->first; ces; ces = ces->next) {
 +              writestruct(wd, DATA, CollectionEngineSettings, 1, ces);
 +
 +              for (CollectionEngineProperty *prop = ces->properties.first; prop; prop = prop->next) {
 +                      switch (prop->type) {
 +                          case COLLECTION_PROP_TYPE_FLOAT:
 +                                  writestruct(wd, DATA, CollectionEnginePropertyFloat, 1, prop);
 +                                  break;
 +                          case COLLECTION_PROP_TYPE_INT:
 +                                  writestruct(wd, DATA, CollectionEnginePropertyInt, 1, prop);
 +                                  break;
 +                          case COLLECTION_PROP_TYPE_BOOL:
 +                                  writestruct(wd, DATA, CollectionEnginePropertyBool, 1, prop);
 +                                  break;
 +                          default:
 +                                  ; /* error: don't know how to write this file */
 +                      }
 +              }
 +      }
 +}
 +
 +static void write_layer_collections(WriteData *wd, ListBase *lb)
 +{
 +      for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
 +              writestruct(wd, DATA, LayerCollection, 1, lc);
 +
 +              writelist(wd, DATA, LinkData, &lc->object_bases);
 +              writelist(wd, DATA, CollectionOverride, &lc->overrides);
 +
 +              write_collection_engine_settings(wd, &lc->engine_settings);
 +
 +              write_collection_engine_settings(wd, &lc->mode_settings);
 +
 +              write_layer_collections(wd, &lc->layer_collections);
 +      }
 +}
 +
 +static void write_render_engines_settings(WriteData *wd, ListBase *lb)
 +{
 +      for (RenderEngineSettings *res = lb->first; res; res = res->next) {
 +              writestruct(wd, DATA, RenderEngineSettings, 1, res);
 +
 +              if (STREQ(res->name, RE_engine_id_BLENDER_CLAY)) {
 +                      writestruct(wd, DATA, RenderEngineSettingsClay, 1, res->data);
 +              }
 +              else {
 +                      /* No engine matched */
 +                      /* error: don't know how to write this file */
 +              }
 +      }
 +}
 +
+ static void write_scene(WriteData *wd, Scene *sce)
  {
-       for (Scene *sce = scebase->first; sce; sce = sce->id.next) {
-               /* write LibData */
-               writestruct(wd, ID_SCE, Scene, 1, sce);
-               write_iddata(wd, &sce->id);
+       /* write LibData */
+       writestruct(wd, ID_SCE, Scene, 1, sce);
+       write_iddata(wd, &sce->id);
  
-               if (sce->adt) {
-                       write_animdata(wd, sce->adt);
-               }
-               write_keyingsets(wd, &sce->keyingsets);
+       if (sce->adt) {
+               write_animdata(wd, sce->adt);
+       }
+       write_keyingsets(wd, &sce->keyingsets);
  
-               /* direct data */
-               for (BaseLegacy *base = sce->base.first; base; base = base->next) {
-                       writestruct(wd, DATA, BaseLegacy, 1, base);
-               }
+       /* direct data */
 -      for (Base *base = sce->base.first; base; base = base->next) {
 -              writestruct(wd, DATA, Base, 1, base);
++      for (BaseLegacy *base = sce->base.first; base; base = base->next) {
++              writestruct(wd, DATA, BaseLegacy, 1, base);
+       }
  
-               ToolSettings *tos = sce->toolsettings;
-               writestruct(wd, DATA, ToolSettings, 1, tos);
-               if (tos->vpaint) {
-                       writestruct(wd, DATA, VPaint, 1, tos->vpaint);
-                       write_paint(wd, &tos->vpaint->paint);
-               }
-               if (tos->wpaint) {
-                       writestruct(wd, DATA, VPaint, 1, tos->wpaint);
-                       write_paint(wd, &tos->wpaint->paint);
-               }
-               if (tos->sculpt) {
-                       writestruct(wd, DATA, Sculpt, 1, tos->sculpt);
-                       write_paint(wd, &tos->sculpt->paint);
-               }
-               if (tos->uvsculpt) {
-                       writestruct(wd, DATA, UvSculpt, 1, tos->uvsculpt);
-                       write_paint(wd, &tos->uvsculpt->paint);
+       ToolSettings *tos = sce->toolsettings;
+       writestruct(wd, DATA, ToolSettings, 1, tos);
+       if (tos->vpaint) {
+               writestruct(wd, DATA, VPaint, 1, tos->vpaint);
+               write_paint(wd, &tos->vpaint->paint);
+       }
+       if (tos->wpaint) {
+               writestruct(wd, DATA, VPaint, 1, tos->wpaint);
+               write_paint(wd, &tos->wpaint->paint);
+       }
+       if (tos->sculpt) {
+               writestruct(wd, DATA, Sculpt, 1, tos->sculpt);
+               write_paint(wd, &tos->sculpt->paint);
+       }
+       if (tos->uvsculpt) {
+               writestruct(wd, DATA, UvSculpt, 1, tos->uvsculpt);
+               write_paint(wd, &tos->uvsculpt->paint);
+       }
+       /* write grease-pencil drawing brushes to file */
+       writelist(wd, DATA, bGPDbrush, &tos->gp_brushes);
+       for (bGPDbrush *brush = tos->gp_brushes.first; brush; brush = brush->next) {
+               if (brush->cur_sensitivity) {
+                       write_curvemapping(wd, brush->cur_sensitivity);
                }
-               /* write grease-pencil drawing brushes to file */
-               writelist(wd, DATA, bGPDbrush, &tos->gp_brushes);
-               for (bGPDbrush *brush = tos->gp_brushes.first; brush; brush = brush->next) {
-                       if (brush->cur_sensitivity) {
-                               write_curvemapping(wd, brush->cur_sensitivity);
-                       }
-                       if (brush->cur_strength) {
-                               write_curvemapping(wd, brush->cur_strength);
-                       }
-                       if (brush->cur_jitter) {
-                               write_curvemapping(wd, brush->cur_jitter);
-                       }
+               if (brush->cur_strength) {
+                       write_curvemapping(wd, brush->cur_strength);
                }
-               /* write grease-pencil custom ipo curve to file */
-               if (tos->gp_interpolate.custom_ipo) {
-                       write_curvemapping(wd, tos->gp_interpolate.custom_ipo);
+               if (brush->cur_jitter) {
+                       write_curvemapping(wd, brush->cur_jitter);
                }
-               
+       }
+       /* write grease-pencil custom ipo curve to file */
+       if (tos->gp_interpolate.custom_ipo) {
+               write_curvemapping(wd, tos->gp_interpolate.custom_ipo);
+       }
  
-               write_paint(wd, &tos->imapaint.paint);
  
-               Editing *ed = sce->ed;
-               if (ed) {
-                       Sequence *seq;
+       write_paint(wd, &tos->imapaint.paint);
  
-                       writestruct(wd, DATA, Editing, 1, ed);
+       Editing *ed = sce->ed;
+       if (ed) {
+               Sequence *seq;
  
-                       /* reset write flags too */
+               writestruct(wd, DATA, Editing, 1, ed);
  
-                       SEQ_BEGIN(ed, seq)
-                       {
-                               if (seq->strip) {
-                                       seq->strip->done = false;
-                               }
-                               writestruct(wd, DATA, Sequence, 1, seq);
-                       }
-                       SEQ_END
+               /* reset write flags too */
  
-                       SEQ_BEGIN(ed, seq)
-                       {
-                               if (seq->strip && seq->strip->done == 0) {
-                                       /* write strip with 'done' at 0 because readfile */
-                                       if (seq->effectdata) {
-                                               switch (seq->type) {
-                                                       case SEQ_TYPE_COLOR:
-                                                               writestruct(wd, DATA, SolidColorVars, 1, seq->effectdata);
-                                                               break;
-                                                       case SEQ_TYPE_SPEED:
-                                                               writestruct(wd, DATA, SpeedControlVars, 1, seq->effectdata);
-                                                               break;
-                                                       case SEQ_TYPE_WIPE:
-                                                               writestruct(wd, DATA, WipeVars, 1, seq->effectdata);
-                                                               break;
-                                                       case SEQ_TYPE_GLOW:
-                                                               writestruct(wd, DATA, GlowVars, 1, seq->effectdata);
-                                                               break;
-                                                       case SEQ_TYPE_TRANSFORM:
-                                                               writestruct(wd, DATA, TransformVars, 1, seq->effectdata);
-                                                               break;
-                                                       case SEQ_TYPE_GAUSSIAN_BLUR:
-                                                               writestruct(wd, DATA, GaussianBlurVars, 1, seq->effectdata);
-                                                               break;
-                                                       case SEQ_TYPE_TEXT:
-                                                               writestruct(wd, DATA, TextVars, 1, seq->effectdata);
-                                                               break;
-                                               }
-                                       }
+               SEQ_BEGIN(ed, seq)
+               {
+                       if (seq->strip) {
+                               seq->strip->done = false;
+                       }
+                       writestruct(wd, DATA, Sequence, 1, seq);
+               }
+               SEQ_END
  
-                                       writestruct(wd, DATA, Stereo3dFormat, 1, seq->stereo3d_format);
+               SEQ_BEGIN(ed, seq)
+               {
+                       if (seq->strip && seq->strip->done == 0) {
+                               /* write strip with 'done' at 0 because readfile */
  
-                                       Strip *strip = seq->strip;
-                                       writestruct(wd, DATA, Strip, 1, strip);
-                                       if (seq->flag & SEQ_USE_CROP && strip->crop) {
-                                               writestruct(wd, DATA, StripCrop, 1, strip->crop);
-                                       }
-                                       if (seq->flag & SEQ_USE_TRANSFORM && strip->transform) {
-                                               writestruct(wd, DATA, StripTransform, 1, strip->transform);
-                                       }
-                                       if (seq->flag & SEQ_USE_PROXY && strip->proxy) {
-                                               writestruct(wd, DATA, StripProxy, 1, strip->proxy);
-                                       }
-                                       if (seq->type == SEQ_TYPE_IMAGE) {
-                                               writestruct(wd, DATA, StripElem,
-                                                           MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem),
-                                                           strip->stripdata);
-                                       }
-                                       else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) {
-                                               writestruct(wd, DATA, StripElem, 1, strip->stripdata);
+                               if (seq->effectdata) {
+                                       switch (seq->type) {
+                                               case SEQ_TYPE_COLOR:
+                                                       writestruct(wd, DATA, SolidColorVars, 1, seq->effectdata);
+                                                       break;
+                                               case SEQ_TYPE_SPEED:
+                                                       writestruct(wd, DATA, SpeedControlVars, 1, seq->effectdata);
+                                                       break;
+                                               case SEQ_TYPE_WIPE:
+                                                       writestruct(wd, DATA, WipeVars, 1, seq->effectdata);
+                                                       break;
+                                               case SEQ_TYPE_GLOW:
+                                                       writestruct(wd, DATA, GlowVars, 1, seq->effectdata);
+                                                       break;
+                                               case SEQ_TYPE_TRANSFORM:
+                                                       writestruct(wd, DATA, TransformVars, 1, seq->effectdata);
+                                                       break;
+                                               case SEQ_TYPE_GAUSSIAN_BLUR:
+                                                       writestruct(wd, DATA, GaussianBlurVars, 1, seq->effectdata);
+                                                       break;
+                                               case SEQ_TYPE_TEXT:
+                                                       writestruct(wd, DATA, TextVars, 1, seq->effectdata);
+                                                       break;
                                        }
-                                       strip->done = true;
                                }
  
-                               if (seq->prop) {
-                                       IDP_WriteProperty(seq->prop, wd);
+                               writestruct(wd, DATA, Stereo3dFormat, 1, seq->stereo3d_format);
+                               Strip *strip = seq->strip;
+                               writestruct(wd, DATA, Strip, 1, strip);
+                               if (seq->flag & SEQ_USE_CROP && strip->crop) {
+                                       writestruct(wd, DATA, StripCrop, 1, strip->crop);
+                               }
+                               if (seq->flag & SEQ_USE_TRANSFORM && strip->transform) {
+                                       writestruct(wd, DATA, StripTransform, 1, strip->transform);
+                               }
+                               if (seq->flag & SEQ_USE_PROXY && strip->proxy) {
+                                       writestruct(wd, DATA, StripProxy, 1, strip->proxy);
+                               }
+                               if (seq->type == SEQ_TYPE_IMAGE) {
+                                       writestruct(wd, DATA, StripElem,
+                                                               MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem),
+                                                               strip->stripdata);
+                               }
+                               else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) {
+                                       writestruct(wd, DATA, StripElem, 1, strip->stripdata);
                                }
  
-                               write_sequence_modifiers(wd, &seq->modifiers);
+                               strip->done = true;
                        }
-                       SEQ_END
  
-                       /* new; meta stack too, even when its nasty restore code */
-                       for (MetaStack *ms = ed->metastack.first; ms; ms = ms->next) {
-                               writestruct(wd, DATA, MetaStack, 1, ms);
+                       if (seq->prop) {
+                               IDP_WriteProperty(seq->prop, wd);
                        }
+                       write_sequence_modifiers(wd, &seq->modifiers);
                }
+               SEQ_END
  
-               if (sce->r.avicodecdata) {
-                       writestruct(wd, DATA, AviCodecData, 1, sce->r.avicodecdata);
-                       if (sce->r.avicodecdata->lpFormat) {
-                               writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat);
-                       }
-                       if (sce->r.avicodecdata->lpParms) {
-                               writedata(wd, DATA, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms);
-                       }
+               /* new; meta stack too, even when its nasty restore code */
+               for (MetaStack *ms = ed->metastack.first; ms; ms = ms->next) {
+                       writestruct(wd, DATA, MetaStack, 1, ms);
                }
+       }
  
-               if (sce->r.qtcodecdata) {
-                       writestruct(wd, DATA, QuicktimeCodecData, 1, sce->r.qtcodecdata);
-                       if (sce->r.qtcodecdata->cdParms) {
-                               writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms);
-                       }
+       if (sce->r.avicodecdata) {
+               writestruct(wd, DATA, AviCodecData, 1, sce->r.avicodecdata);
+               if (sce->r.avicodecdata->lpFormat) {
+                       writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat);
                }
-               if (sce->r.ffcodecdata.properties) {
-                       IDP_WriteProperty(sce->r.ffcodecdata.properties, wd);
+               if (sce->r.avicodecdata->lpParms) {
+                       writedata(wd, DATA, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms);
                }
+       }
  
-               /* writing dynamic list of TimeMarkers to the blend file */
-               for (TimeMarker *marker = sce->markers.first; marker; marker = marker->next) {
-                       writestruct(wd, DATA, TimeMarker, 1, marker);
+       if (sce->r.qtcodecdata) {
+               writestruct(wd, DATA, QuicktimeCodecData, 1, sce->r.qtcodecdata);
+               if (sce->r.qtcodecdata->cdParms) {
+                       writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms);
                }
+       }
+       if (sce->r.ffcodecdata.properties) {
+               IDP_WriteProperty(sce->r.ffcodecdata.properties, wd);
+       }
  
-               /* writing dynamic list of TransformOrientations to the blend file */
-               for (TransformOrientation *ts = sce->transform_spaces.first; ts; ts = ts->next) {
-                       writestruct(wd, DATA, TransformOrientation, 1, ts);
-               }
+       /* writing dynamic list of TimeMarkers to the blend file */
+       for (TimeMarker *marker = sce->markers.first; marker; marker = marker->next) {
+               writestruct(wd, DATA, TimeMarker, 1, marker);
+       }
  
-               for (SceneRenderLayer *srl = sce->r.layers.first; srl; srl = srl->next) {
-                       writestruct(wd, DATA, SceneRenderLayer, 1, srl);
-                       for (FreestyleModuleConfig *fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
-                               writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc);
-                       }
-                       for (FreestyleLineSet *fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
-                               writestruct(wd, DATA, FreestyleLineSet, 1, fls);
-                       }
-               }
+       /* writing dynamic list of TransformOrientations to the blend file */
+       for (TransformOrientation *ts = sce->transform_spaces.first; ts; ts = ts->next) {
+               writestruct(wd, DATA, TransformOrientation, 1, ts);
+       }
  
-               /* writing MultiView to the blend file */
-               for (SceneRenderView *srv = sce->r.views.first; srv; srv = srv->next) {
-                       writestruct(wd, DATA, SceneRenderView, 1, srv);
+       for (SceneRenderLayer *srl = sce->r.layers.first; srl; srl = srl->next) {
+               writestruct(wd, DATA, SceneRenderLayer, 1, srl);
+               for (FreestyleModuleConfig *fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
+                       writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc);
                }
-               if (sce->nodetree) {
-                       writestruct(wd, DATA, bNodeTree, 1, sce->nodetree);
-                       write_nodetree(wd, sce->nodetree);
+               for (FreestyleLineSet *fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
+                       writestruct(wd, DATA, FreestyleLineSet, 1, fls);
                }
+       }
  
-               write_view_settings(wd, &sce->view_settings);
+       /* writing MultiView to the blend file */
+       for (SceneRenderView *srv = sce->r.views.first; srv; srv = srv->next) {
+               writestruct(wd, DATA, SceneRenderView, 1, srv);
+       }
  
-               /* writing RigidBodyWorld data to the blend file */
-               if (sce->rigidbody_world) {
-                       writestruct(wd, DATA, RigidBodyWorld, 1, sce->rigidbody_world);
-                       writestruct(wd, DATA, EffectorWeights, 1, sce->rigidbody_world->effector_weights);
-                       write_pointcaches(wd, &(sce->rigidbody_world->ptcaches));
-               }
+       if (sce->nodetree) {
+               writestruct(wd, DATA, bNodeTree, 1, sce->nodetree);
+               write_nodetree_nolib(wd, sce->nodetree);
+       }
  
-               write_previews(wd, sce->preview);
-               write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve);
-               write_scene_collection(wd, sce->collection);
+       write_view_settings(wd, &sce->view_settings);
  
-               for (SceneLayer *sl = sce->render_layers.first; sl; sl = sl->next) {
-                       writestruct(wd, DATA, SceneLayer, 1, sl);
-                       writelist(wd, DATA, Base, &sl->object_bases);
-                       write_layer_collections(wd, &sl->layer_collections);
-               }
+       /* writing RigidBodyWorld data to the blend file */
+       if (sce->rigidbody_world) {
+               writestruct(wd, DATA, RigidBodyWorld, 1, sce->rigidbody_world);
+               writestruct(wd, DATA, EffectorWeights, 1, sce->rigidbody_world->effector_weights);
+               write_pointcaches(wd, &(sce->rigidbody_world->ptcaches));
+       }
  
-               write_render_engines_settings(wd, &sce->engines_settings);
+       write_previews(wd, sce->preview);
+       write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve);
++      write_scene_collection(wd, sce->collection);
 +
++      for (SceneLayer *sl = sce->render_layers.first; sl; sl = sl->next) {
++              writestruct(wd, DATA, SceneLayer, 1, sl);
++              writelist(wd, DATA, Base, &sl->object_bases);
++              write_layer_collections(wd, &sl->layer_collections);
 +      }
 +
-       mywrite_flush(wd);
++      write_render_engines_settings(wd, &sce->engines_settings);
  }
  
- static void write_gpencils(WriteData *wd, ListBase *lb)
+ static void write_gpencil(WriteData *wd, bGPdata *gpd)
  {
-       for (bGPdata *gpd = lb->first; gpd; gpd = gpd->id.next) {
-               if (gpd->id.us > 0 || wd->current) {
-                       /* write gpd data block to file */
-                       writestruct(wd, ID_GD, bGPdata, 1, gpd);
-                       write_iddata(wd, &gpd->id);
+       if (gpd->id.us > 0 || wd->current) {
+               /* write gpd data block to file */
+               writestruct(wd, ID_GD, bGPdata, 1, gpd);
+               write_iddata(wd, &gpd->id);
  
-                       if (gpd->adt) {
-                               write_animdata(wd, gpd->adt);
-                       }
+               if (gpd->adt) {
+                       write_animdata(wd, gpd->adt);
+               }
  
-                       /* write grease-pencil layers to file */
-                       writelist(wd, DATA, bGPDlayer, &gpd->layers);
-                       for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-                               /* write this layer's frames to file */
-                               writelist(wd, DATA, bGPDframe, &gpl->frames);
-                               for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-                                       /* write strokes */
-                                       writelist(wd, DATA, bGPDstroke, &gpf->strokes);
-                                       for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-                                               writestruct(wd, DATA, bGPDspoint, gps->totpoints, gps->points);
-                                       }
+               /* write grease-pencil layers to file */
+               writelist(wd, DATA, bGPDlayer, &gpd->layers);
+               for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+                       /* write this layer's frames to file */
+                       writelist(wd, DATA, bGPDframe, &gpl->frames);
+                       for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+                               /* write strokes */
+                               writelist(wd, DATA, bGPDstroke, &gpf->strokes);
+                               for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+                                       writestruct(wd, DATA, bGPDspoint, gps->totpoints, gps->points);
                                }
                        }
+               }
  
-                       /* write grease-pencil palettes */
-                       writelist(wd, DATA, bGPDpalette, &gpd->palettes);
-                       for (bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
-                               writelist(wd, DATA, bGPDpalettecolor, &palette->colors);
-                       }
+               /* write grease-pencil palettes */
+               writelist(wd, DATA, bGPDpalette, &gpd->palettes);
+               for (bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
+                       writelist(wd, DATA, bGPDpalettecolor, &palette->colors);
                }
        }
-       mywrite_flush(wd);
  }
  
- static void write_windowmanagers(WriteData *wd, ListBase *lb)
+ static void write_windowmanager(WriteData *wd, wmWindowManager *wm)
  {
-       for (wmWindowManager *wm = lb->first; wm; wm = wm->id.next) {
-               writestruct(wd, ID_WM, wmWindowManager, 1, wm);
-               write_iddata(wd, &wm->id);
+       writestruct(wd, ID_WM, wmWindowManager, 1, wm);
+       write_iddata(wd, &wm->id);
  
-               for (wmWindow *win = wm->windows.first; win; win = win->next) {
-                       writestruct(wd, DATA, wmWindow, 1, win);
-                       writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format);
-               }
+       for (wmWindow *win = wm->windows.first; win; win = win->next) {
+               writestruct(wd, DATA, wmWindow, 1, win);
+               writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format);
        }
-       /* typically flushing wouldn't be needed however this data _always_ changes,
-        * so flush here for more efficient undo. */
-       mywrite_flush(wd);
  }
  
  static void write_region(WriteData *wd, ARegion *ar, int spacetype)
@@@ -3021,169 -2865,165 +2957,167 @@@ static void write_soops(WriteData *wd, 
        }
  }
  
- static void write_screens(WriteData *wd, ListBase *scrbase)
+ static void write_screen(WriteData *wd, bScreen *sc)
  {
-       for (bScreen *sc = scrbase->first; sc; sc = sc->id.next) {
-               /* write LibData */
-               /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
-               writestruct(wd, ID_SCRN, bScreen, 1, sc);
-               write_iddata(wd, &sc->id);
+       /* write LibData */
+       /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
+       writestruct(wd, ID_SCRN, bScreen, 1, sc);
+       write_iddata(wd, &sc->id);
  
-               write_previews(wd, sc->preview);
-               /* direct data */
-               for (ScrVert *sv = sc->vertbase.first; sv; sv = sv->next) {
-                       writestruct(wd, DATA, ScrVert, 1, sv);
-               }
++      write_previews(wd, sc->preview);
 +
-               for (ScrEdge *se = sc->edgebase.first; se; se = se->next) {
-                       writestruct(wd, DATA, ScrEdge, 1, se);
-               }
+       /* direct data */
+       for (ScrVert *sv = sc->vertbase.first; sv; sv = sv->next) {
+               writestruct(wd, DATA, ScrVert, 1, sv);
+       }
  
-               for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
-                       SpaceLink *sl;
-                       Panel *pa;
-                       uiList *ui_list;
-                       uiPreview *ui_preview;
-                       PanelCategoryStack *pc_act;
-                       ARegion *ar;
+       for (ScrEdge *se = sc->edgebase.first; se; se = se->next) {
+               writestruct(wd, DATA, ScrEdge, 1, se);
+       }
  
-                       writestruct(wd, DATA, ScrArea, 1, sa);
+       for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
+               SpaceLink *sl;
+               Panel *pa;
+               uiList *ui_list;
+               uiPreview *ui_preview;
+               PanelCategoryStack *pc_act;
+               ARegion *ar;
  
-                       for (ar = sa->regionbase.first; ar; ar = ar->next) {
-                               write_region(wd, ar, sa->spacetype);
+               writestruct(wd, DATA, ScrArea, 1, sa);
  
-                               for (pa = ar->panels.first; pa; pa = pa->next) {
-                                       writestruct(wd, DATA, Panel, 1, pa);
-                               }
+               for (ar = sa->regionbase.first; ar; ar = ar->next) {
+                       write_region(wd, ar, sa->spacetype);
  
-                               for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) {
-                                       writestruct(wd, DATA, PanelCategoryStack, 1, pc_act);
-                               }
-                               for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
-                                       write_uilist(wd, ui_list);
-                               }
-                               for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) {
-                                       writestruct(wd, DATA, uiPreview, 1, ui_preview);
-                               }
+                       for (pa = ar->panels.first; pa; pa = pa->next) {
+                               writestruct(wd, DATA, Panel, 1, pa);
                        }
  
-                       for (sl = sa->spacedata.first; sl; sl = sl->next) {
-                               for (ar = sl->regionbase.first; ar; ar = ar->next) {
-                                       write_region(wd, ar, sl->spacetype);
-                               }
-                               if (sl->spacetype == SPACE_VIEW3D) {
-                                       View3D *v3d = (View3D *)sl;
-                                       BGpic *bgpic;
-                                       writestruct(wd, DATA, View3D, 1, v3d);
-                                       for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-                                               writestruct(wd, DATA, BGpic, 1, bgpic);
-                                       }
-                                       if (v3d->localvd) {
-                                               writestruct(wd, DATA, View3D, 1, v3d->localvd);
-                                       }
+                       for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) {
+                               writestruct(wd, DATA, PanelCategoryStack, 1, pc_act);
+                       }
  
-                                       if (v3d->fx_settings.ssao) {
-                                               writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao);
-                                       }
-                                       if (v3d->fx_settings.dof) {
-                                               writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof);
-                                       }
-                               }
-                               else if (sl->spacetype == SPACE_IPO) {
-                                       SpaceIpo *sipo = (SpaceIpo *)sl;
-                                       ListBase tmpGhosts = sipo->ghostCurves;
+                       for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
+                               write_uilist(wd, ui_list);
+                       }
  
-                                       /* temporarily disable ghost curves when saving */
-                                       sipo->ghostCurves.first = sipo->ghostCurves.last = NULL;
+                       for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) {
+                               writestruct(wd, DATA, uiPreview, 1, ui_preview);
+                       }
+               }
  
-                                       writestruct(wd, DATA, SpaceIpo, 1, sl);
-                                       if (sipo->ads) {
-                                               writestruct(wd, DATA, bDopeSheet, 1, sipo->ads);
-                                       }
+               for (sl = sa->spacedata.first; sl; sl = sl->next) {
+                       for (ar = sl->regionbase.first; ar; ar = ar->next) {
+                               write_region(wd, ar, sl->spacetype);
+                       }
  
-                                       /* reenable ghost curves */
-                                       sipo->ghostCurves = tmpGhosts;
+                       if (sl->spacetype == SPACE_VIEW3D) {
+                               View3D *v3d = (View3D *)sl;
+                               BGpic *bgpic;
+                               writestruct(wd, DATA, View3D, 1, v3d);
+                               for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
+                                       writestruct(wd, DATA, BGpic, 1, bgpic);
                                }
-                               else if (sl->spacetype == SPACE_BUTS) {
-                                       writestruct(wd, DATA, SpaceButs, 1, sl);
+                               if (v3d->localvd) {
+                                       writestruct(wd, DATA, View3D, 1, v3d->localvd);
                                }
-                               else if (sl->spacetype == SPACE_FILE) {
-                                       SpaceFile *sfile = (SpaceFile *)sl;
  
-                                       writestruct(wd, DATA, SpaceFile, 1, sl);
-                                       if (sfile->params) {
-                                               writestruct(wd, DATA, FileSelectParams, 1, sfile->params);
-                                       }
-                               }
-                               else if (sl->spacetype == SPACE_SEQ) {
-                                       writestruct(wd, DATA, SpaceSeq, 1, sl);
-                               }
-                               else if (sl->spacetype == SPACE_OUTLINER) {
-                                       SpaceOops *so = (SpaceOops *)sl;
-                                       write_soops(wd, so);
-                               }
-                               else if (sl->spacetype == SPACE_IMAGE) {
-                                       writestruct(wd, DATA, SpaceImage, 1, sl);
+                               if (v3d->fx_settings.ssao) {
+                                       writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao);
                                }
-                               else if (sl->spacetype == SPACE_TEXT) {
-                                       writestruct(wd, DATA, SpaceText, 1, sl);
+                               if (v3d->fx_settings.dof) {
+                                       writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof);
                                }
-                               else if (sl->spacetype == SPACE_SCRIPT) {
-                                       SpaceScript *scr = (SpaceScript *)sl;
-                                       scr->but_refs = NULL;
-                                       writestruct(wd, DATA, SpaceScript, 1, sl);
-                               }
-                               else if (sl->spacetype == SPACE_ACTION) {
-                                       writestruct(wd, DATA, SpaceAction, 1, sl);
-                               }
-                               else if (sl->spacetype == SPACE_NLA) {
-                                       SpaceNla *snla = (SpaceNla *)sl;
+                       }
+                       else if (sl->spacetype == SPACE_IPO) {
+                               SpaceIpo *sipo = (SpaceIpo *)sl;
+                               ListBase tmpGhosts = sipo->ghostCurves;
  
-                                       writestruct(wd, DATA, SpaceNla, 1, snla);
-                                       if (snla->ads) {
-                                               writestruct(wd, DATA, bDopeSheet, 1, snla->ads);
-                                       }
-                               }
-                               else if (sl->spacetype == SPACE_TIME) {
-                                       writestruct(wd, DATA, SpaceTime, 1, sl);
-                               }
-                               else if (sl->spacetype == SPACE_NODE) {
-                                       SpaceNode *snode = (SpaceNode *)sl;
-                                       bNodeTreePath *path;
-                                       writestruct(wd, DATA, SpaceNode, 1, snode);
+                               /* temporarily disable ghost curves when saving */
+                               sipo->ghostCurves.first = sipo->ghostCurves.last = NULL;
  
-                                       for (path = snode->treepath.first; path; path = path->next) {
-                                               writestruct(wd, DATA, bNodeTreePath, 1, path);
-                                       }
+                               writestruct(wd, DATA, SpaceIpo, 1, sl);
+                               if (sipo->ads) {
+                                       writestruct(wd, DATA, bDopeSheet, 1, sipo->ads);
                                }
-                               else if (sl->spacetype == SPACE_LOGIC) {
-                                       writestruct(wd, DATA, SpaceLogic, 1, sl);
-                               }
-                               else if (sl->spacetype == SPACE_CONSOLE) {
-                                       SpaceConsole *con = (SpaceConsole *)sl;
-                                       ConsoleLine *cl;
-                                       for (cl = con->history.first; cl; cl = cl->next) {
-                                               /* 'len_alloc' is invalid on write, set from 'len' on read */
-                                               writestruct(wd, DATA, ConsoleLine, 1, cl);
-                                               writedata(wd, DATA, cl->len + 1, cl->line);
-                                       }
-                                       writestruct(wd, DATA, SpaceConsole, 1, sl);
  
+                               /* reenable ghost curves */
+                               sipo->ghostCurves = tmpGhosts;
+                       }
+                       else if (sl->spacetype == SPACE_BUTS) {
+                               writestruct(wd, DATA, SpaceButs, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_FILE) {
+                               SpaceFile *sfile = (SpaceFile *)sl;
+                               writestruct(wd, DATA, SpaceFile, 1, sl);
+                               if (sfile->params) {
+                                       writestruct(wd, DATA, FileSelectParams, 1, sfile->params);
                                }
-                               else if (sl->spacetype == SPACE_USERPREF) {
-                                       writestruct(wd, DATA, SpaceUserPref, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_SEQ) {
+                               writestruct(wd, DATA, SpaceSeq, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_OUTLINER) {
+                               SpaceOops *so = (SpaceOops *)sl;
+                               write_soops(wd, so);
+                       }
+                       else if (sl->spacetype == SPACE_IMAGE) {
+                               writestruct(wd, DATA, SpaceImage, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_TEXT) {
+                               writestruct(wd, DATA, SpaceText, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_SCRIPT) {
+                               SpaceScript *scr = (SpaceScript *)sl;
+                               scr->but_refs = NULL;
+                               writestruct(wd, DATA, SpaceScript, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_ACTION) {
+                               writestruct(wd, DATA, SpaceAction, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_NLA) {
+                               SpaceNla *snla = (SpaceNla *)sl;
+                               writestruct(wd, DATA, SpaceNla, 1, snla);
+                               if (snla->ads) {
+                                       writestruct(wd, DATA, bDopeSheet, 1, snla->ads);
                                }
-                               else if (sl->spacetype == SPACE_CLIP) {
-                                       writestruct(wd, DATA, SpaceClip, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_TIME) {
+                               writestruct(wd, DATA, SpaceTime, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_NODE) {
+                               SpaceNode *snode = (SpaceNode *)sl;
+                               bNodeTreePath *path;
+                               writestruct(wd, DATA, SpaceNode, 1, snode);
+                               for (path = snode->treepath.first; path; path = path->next) {
+                                       writestruct(wd, DATA, bNodeTreePath, 1, path);
                                }
-                               else if (sl->spacetype == SPACE_INFO) {
-                                       writestruct(wd, DATA, SpaceInfo, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_LOGIC) {
+                               writestruct(wd, DATA, SpaceLogic, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_CONSOLE) {
+                               SpaceConsole *con = (SpaceConsole *)sl;
+                               ConsoleLine *cl;
+                               for (cl = con->history.first; cl; cl = cl->next) {
+                                       /* 'len_alloc' is invalid on write, set from 'len' on read */
+                                       writestruct(wd, DATA, ConsoleLine, 1, cl);
+                                       writedata(wd, DATA, cl->len + 1, cl->line);
                                }
+                               writestruct(wd, DATA, SpaceConsole, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_USERPREF) {
+                               writestruct(wd, DATA, SpaceUserPref, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_CLIP) {
+                               writestruct(wd, DATA, SpaceClip, 1, sl);
+                       }
+                       else if (sl->spacetype == SPACE_INFO) {
+                               writestruct(wd, DATA, SpaceInfo, 1, sl);
                        }
                }
        }