Cleanup: Blendwrite: Move code deciding if an ID should be written out of ID callbacks.

This was not really useful, and added estra useless steps in case and ID
should not actually be written.

Further more, it prevented clearing the usercount on write, which can be
cause a false positive 'chanhged' detection in undo/redo case.
This commit is contained in:
2021-08-19 11:13:55 +02:00
parent d5776f4829
commit 0f49e4832c
35 changed files with 695 additions and 730 deletions

View File

@@ -186,7 +186,7 @@ static void action_foreach_id(ID *id, LibraryForeachIDData *data)
static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void action_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
bAction *act = (bAction *)id; bAction *act = (bAction *)id;
if (act->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, bAction, id_address, &act->id); BLO_write_id_struct(writer, bAction, id_address, &act->id);
BKE_id_blend_write(writer, &act->id); BKE_id_blend_write(writer, &act->id);
@@ -202,7 +202,6 @@ static void action_blend_write(BlendWriter *writer, ID *id, const void *id_addre
BKE_previewimg_blend_write(writer, act->preview); BKE_previewimg_blend_write(writer, act->preview);
} }
}
static void action_blend_read_data(BlendDataReader *reader, ID *id) static void action_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -212,7 +212,7 @@ static void write_bone(BlendWriter *writer, Bone *bone)
static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
bArmature *arm = (bArmature *)id; bArmature *arm = (bArmature *)id;
if (arm->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
arm->bonehash = NULL; arm->bonehash = NULL;
arm->edbo = NULL; arm->edbo = NULL;
@@ -232,7 +232,6 @@ static void armature_blend_write(BlendWriter *writer, ID *id, const void *id_add
write_bone(writer, bone); write_bone(writer, bone);
} }
} }
}
static void direct_link_bones(BlendDataReader *reader, Bone *bone) static void direct_link_bones(BlendDataReader *reader, Bone *bone)
{ {

View File

@@ -202,7 +202,7 @@ static void brush_foreach_id(ID *id, LibraryForeachIDData *data)
static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Brush *brush = (Brush *)id; Brush *brush = (Brush *)id;
if (brush->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Brush, id_address, &brush->id); BLO_write_id_struct(writer, Brush, id_address, &brush->id);
BKE_id_blend_write(writer, &brush->id); BKE_id_blend_write(writer, &brush->id);
@@ -245,7 +245,6 @@ static void brush_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BLO_write_struct(writer, ColorBand, brush->gradient); BLO_write_struct(writer, ColorBand, brush->gradient);
} }
} }
}
static void brush_blend_read_data(BlendDataReader *reader, ID *id) static void brush_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -97,7 +97,7 @@ static void cache_file_free_data(ID *id)
static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
CacheFile *cache_file = (CacheFile *)id; CacheFile *cache_file = (CacheFile *)id;
if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&cache_file->object_paths); BLI_listbase_clear(&cache_file->object_paths);
cache_file->handle = NULL; cache_file->handle = NULL;
@@ -111,7 +111,6 @@ static void cache_file_blend_write(BlendWriter *writer, ID *id, const void *id_a
BKE_animdata_blend_write(writer, cache_file->adt); BKE_animdata_blend_write(writer, cache_file->adt);
} }
} }
}
static void cache_file_blend_read_data(BlendDataReader *reader, ID *id) static void cache_file_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -122,7 +122,7 @@ static void camera_foreach_id(ID *id, LibraryForeachIDData *data)
static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Camera *cam = (Camera *)id; Camera *cam = (Camera *)id;
if (cam->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */ /* write LibData */
BLO_write_id_struct(writer, Camera, id_address, &cam->id); BLO_write_id_struct(writer, Camera, id_address, &cam->id);
BKE_id_blend_write(writer, &cam->id); BKE_id_blend_write(writer, &cam->id);
@@ -135,7 +135,6 @@ static void camera_blend_write(BlendWriter *writer, ID *id, const void *id_addre
BLO_write_struct(writer, CameraBGImage, bgpic); BLO_write_struct(writer, CameraBGImage, bgpic);
} }
} }
}
static void camera_blend_read_data(BlendDataReader *reader, ID *id) static void camera_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -214,7 +214,7 @@ void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collectio
static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Collection *collection = (Collection *)id; Collection *collection = (Collection *)id;
if (collection->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */ /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE;
collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED; collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE_INSTANCED;
@@ -228,7 +228,6 @@ static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_a
BKE_collection_blend_write_nolib(writer, collection); BKE_collection_blend_write_nolib(writer, collection);
} }
}
#ifdef USE_COLLECTION_COMPAT_28 #ifdef USE_COLLECTION_COMPAT_28
void BKE_collection_compat_blend_read_data(BlendDataReader *reader, SceneCollection *sc) void BKE_collection_compat_blend_read_data(BlendDataReader *reader, SceneCollection *sc)

View File

@@ -146,7 +146,7 @@ static void curve_foreach_id(ID *id, LibraryForeachIDData *data)
static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Curve *cu = (Curve *)id; Curve *cu = (Curve *)id;
if (cu->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
cu->editnurb = NULL; cu->editnurb = NULL;
cu->editfont = NULL; cu->editfont = NULL;
@@ -192,7 +192,6 @@ static void curve_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BKE_curveprofile_blend_write(writer, cu->bevel_profile); BKE_curveprofile_blend_write(writer, cu->bevel_profile);
} }
} }
}
static void switch_endian_knots(Nurb *nu) static void switch_endian_knots(Nurb *nu)
{ {

View File

@@ -126,7 +126,7 @@ static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{ {
VFont *vf = (VFont *)id; VFont *vf = (VFont *)id;
const bool is_undo = BLO_write_is_undo(writer); const bool is_undo = BLO_write_is_undo(writer);
if (vf->id.us > 0 || is_undo) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
vf->data = NULL; vf->data = NULL;
vf->temp_pf = NULL; vf->temp_pf = NULL;
@@ -143,7 +143,6 @@ static void vfont_blend_write(BlendWriter *writer, ID *id, const void *id_addres
/* direct data */ /* direct data */
BKE_packedfile_blend_write(writer, vf->packedfile); BKE_packedfile_blend_write(writer, vf->packedfile);
} }
}
static void vfont_blend_read_data(BlendDataReader *reader, ID *id) static void vfont_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -150,7 +150,7 @@ static void greasepencil_foreach_id(ID *id, LibraryForeachIDData *data)
static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
bGPdata *gpd = (bGPdata *)id; bGPdata *gpd = (bGPdata *)id;
if (gpd->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */ /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
/* XXX not sure why the whole run-time data is not cleared in reading code, /* XXX not sure why the whole run-time data is not cleared in reading code,
* for now mimicking it here. */ * for now mimicking it here. */
@@ -195,7 +195,6 @@ static void greasepencil_blend_write(BlendWriter *writer, ID *id, const void *id
} }
} }
} }
}
void BKE_gpencil_blend_read_data(BlendDataReader *reader, bGPdata *gpd) void BKE_gpencil_blend_read_data(BlendDataReader *reader, bGPdata *gpd)
{ {

View File

@@ -114,7 +114,7 @@ static void hair_foreach_id(ID *id, LibraryForeachIDData *data)
static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Hair *hair = (Hair *)id; Hair *hair = (Hair *)id;
if (hair->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); CustomData_blend_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
@@ -141,7 +141,6 @@ static void hair_blend_write(BlendWriter *writer, ID *id, const void *id_address
MEM_freeN(clayers); MEM_freeN(clayers);
} }
} }
}
static void hair_blend_read_data(BlendDataReader *reader, ID *id) static void hair_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -229,7 +229,7 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{ {
Image *ima = (Image *)id; Image *ima = (Image *)id;
const bool is_undo = BLO_write_is_undo(writer); const bool is_undo = BLO_write_is_undo(writer);
if (ima->id.us > 0 || is_undo) {
ImagePackedFile *imapf; ImagePackedFile *imapf;
BLI_assert(ima->packedfile == NULL); BLI_assert(ima->packedfile == NULL);
@@ -267,7 +267,6 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BLO_write_struct_list(writer, RenderSlot, &ima->renderslots); BLO_write_struct_list(writer, RenderSlot, &ima->renderslots);
} }
}
static void image_blend_read_data(BlendDataReader *reader, ID *id) static void image_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -114,7 +114,7 @@ static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_add
{ {
Key *key = (Key *)id; Key *key = (Key *)id;
const bool is_undo = BLO_write_is_undo(writer); const bool is_undo = BLO_write_is_undo(writer);
if (key->id.us > 0 || is_undo) {
/* write LibData */ /* write LibData */
BLO_write_id_struct(writer, Key, id_address, &key->id); BLO_write_id_struct(writer, Key, id_address, &key->id);
BKE_id_blend_write(writer, &key->id); BKE_id_blend_write(writer, &key->id);
@@ -137,7 +137,6 @@ static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_add
} }
} }
} }
}
/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */ /* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */
#define IPO_FLOAT 4 #define IPO_FLOAT 4

View File

@@ -137,7 +137,7 @@ static void lattice_foreach_id(ID *id, LibraryForeachIDData *data)
static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Lattice *lt = (Lattice *)id; Lattice *lt = (Lattice *)id;
if (lt->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
lt->editlatt = NULL; lt->editlatt = NULL;
lt->batch_cache = NULL; lt->batch_cache = NULL;
@@ -157,7 +157,6 @@ static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_addr
BKE_defbase_blend_write(writer, &lt->vertex_group_names); BKE_defbase_blend_write(writer, &lt->vertex_group_names);
BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
} }
}
static void lattice_blend_read_data(BlendDataReader *reader, ID *id) static void lattice_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -136,7 +136,7 @@ static void light_foreach_id(ID *id, LibraryForeachIDData *data)
static void light_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void light_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Light *la = (Light *)id; Light *la = (Light *)id;
if (la->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */ /* write LibData */
BLO_write_id_struct(writer, Light, id_address, &la->id); BLO_write_id_struct(writer, Light, id_address, &la->id);
BKE_id_blend_write(writer, &la->id); BKE_id_blend_write(writer, &la->id);
@@ -157,7 +157,6 @@ static void light_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BKE_previewimg_blend_write(writer, la->preview); BKE_previewimg_blend_write(writer, la->preview);
} }
}
static void light_blend_read_data(BlendDataReader *reader, ID *id) static void light_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -60,7 +60,7 @@ static void lightprobe_foreach_id(ID *id, LibraryForeachIDData *data)
static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
LightProbe *prb = (LightProbe *)id; LightProbe *prb = (LightProbe *)id;
if (prb->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */ /* write LibData */
BLO_write_id_struct(writer, LightProbe, id_address, &prb->id); BLO_write_id_struct(writer, LightProbe, id_address, &prb->id);
BKE_id_blend_write(writer, &prb->id); BKE_id_blend_write(writer, &prb->id);
@@ -69,7 +69,6 @@ static void lightprobe_blend_write(BlendWriter *writer, ID *id, const void *id_a
BKE_animdata_blend_write(writer, prb->adt); BKE_animdata_blend_write(writer, prb->adt);
} }
} }
}
static void lightprobe_blend_read_data(BlendDataReader *reader, ID *id) static void lightprobe_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -457,7 +457,7 @@ static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *mo
static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id;
if (linestyle->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id); BLO_write_id_struct(writer, FreestyleLineStyle, id_address, &linestyle->id);
BKE_id_blend_write(writer, &linestyle->id); BKE_id_blend_write(writer, &linestyle->id);
@@ -479,7 +479,6 @@ static void linestyle_blend_write(BlendWriter *writer, ID *id, const void *id_ad
ntreeBlendWrite(writer, linestyle->nodetree); ntreeBlendWrite(writer, linestyle->nodetree);
} }
} }
}
static void direct_link_linestyle_color_modifier(BlendDataReader *reader, static void direct_link_linestyle_color_modifier(BlendDataReader *reader,
LineStyleModifier *modifier) LineStyleModifier *modifier)

View File

@@ -101,7 +101,7 @@ static void mask_foreach_id(ID *id, LibraryForeachIDData *data)
static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Mask *mask = (Mask *)id; Mask *mask = (Mask *)id;
if (mask->id.us > 0 || BLO_write_is_undo(writer)) {
MaskLayer *masklay; MaskLayer *masklay;
BLO_write_id_struct(writer, Mask, id_address, &mask->id); BLO_write_id_struct(writer, Mask, id_address, &mask->id);
@@ -145,7 +145,6 @@ static void mask_blend_write(BlendWriter *writer, ID *id, const void *id_address
} }
} }
} }
}
static void mask_blend_read_data(BlendDataReader *reader, ID *id) static void mask_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -179,7 +179,7 @@ static void material_foreach_id(ID *id, LibraryForeachIDData *data)
static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void material_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Material *ma = (Material *)id; Material *ma = (Material *)id;
if (ma->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
ma->texpaintslot = NULL; ma->texpaintslot = NULL;
BLI_listbase_clear(&ma->gpumaterial); BLI_listbase_clear(&ma->gpumaterial);
@@ -205,7 +205,6 @@ static void material_blend_write(BlendWriter *writer, ID *id, const void *id_add
BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style); BLO_write_struct(writer, MaterialGPencilStyle, ma->gp_style);
} }
} }
}
static void material_blend_read_data(BlendDataReader *reader, ID *id) static void material_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -119,7 +119,7 @@ static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
MetaBall *mb = (MetaBall *)id; MetaBall *mb = (MetaBall *)id;
if (mb->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&mb->disp); BLI_listbase_clear(&mb->disp);
mb->editelems = NULL; mb->editelems = NULL;
@@ -142,7 +142,6 @@ static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_add
BLO_write_struct(writer, MetaElem, ml); BLO_write_struct(writer, MetaElem, ml);
} }
} }
}
static void metaball_blend_read_data(BlendDataReader *reader, ID *id) static void metaball_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -179,7 +179,7 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
{ {
Mesh *mesh = (Mesh *)id; Mesh *mesh = (Mesh *)id;
const bool is_undo = BLO_write_is_undo(writer); const bool is_undo = BLO_write_is_undo(writer);
if (mesh->id.us > 0 || is_undo) {
CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE];
CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE];
@@ -216,14 +216,10 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
players = players_buff; players = players_buff;
} }
else { else {
CustomData_blend_write_prepare( CustomData_blend_write_prepare(&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
&mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff)); CustomData_blend_write_prepare(&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
CustomData_blend_write_prepare( CustomData_blend_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
&mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff)); CustomData_blend_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
CustomData_blend_write_prepare(
&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
CustomData_blend_write_prepare(
&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
} }
BLO_write_id_struct(writer, Mesh, id_address, &mesh->id); BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
@@ -268,7 +264,6 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
#undef CD_LAYERS_FREE #undef CD_LAYERS_FREE
} }
}
static void mesh_blend_read_data(BlendDataReader *reader, ID *id) static void mesh_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -206,7 +206,7 @@ static void write_movieReconstruction(BlendWriter *writer,
static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
MovieClip *clip = (MovieClip *)id; MovieClip *clip = (MovieClip *)id;
if (clip->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
clip->anim = NULL; clip->anim = NULL;
clip->tracking_context = NULL; clip->tracking_context = NULL;
@@ -237,7 +237,6 @@ static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_ad
object = object->next; object = object->next;
} }
} }
}
static void direct_link_movieReconstruction(BlendDataReader *reader, static void direct_link_movieReconstruction(BlendDataReader *reader,
MovieTrackingReconstruction *reconstruction) MovieTrackingReconstruction *reconstruction)

View File

@@ -606,7 +606,7 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
bNodeTree *ntree = (bNodeTree *)id; bNodeTree *ntree = (bNodeTree *)id;
if (ntree->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
ntree->init = 0; /* to set callbacks and force setting types */ ntree->init = 0; /* to set callbacks and force setting types */
ntree->is_updating = false; ntree->is_updating = false;
@@ -619,7 +619,6 @@ static void ntree_blend_write(BlendWriter *writer, ID *id, const void *id_addres
ntreeBlendWrite(writer, ntree); ntreeBlendWrite(writer, ntree);
} }
}
static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock) static void direct_link_node_socket(BlendDataReader *reader, bNodeSocket *sock)
{ {

View File

@@ -523,7 +523,7 @@ static void object_blend_write(BlendWriter *writer, ID *id, const void *id_addre
Object *ob = (Object *)id; Object *ob = (Object *)id;
const bool is_undo = BLO_write_is_undo(writer); const bool is_undo = BLO_write_is_undo(writer);
if (ob->id.us > 0 || is_undo) {
/* Clean up, important in undo case to reduce false detection of changed data-blocks. */ /* Clean up, important in undo case to reduce false detection of changed data-blocks. */
BKE_object_runtime_reset(ob); BKE_object_runtime_reset(ob);
@@ -549,8 +549,7 @@ static void object_blend_write(BlendWriter *writer, ID *id, const void *id_addre
if (ob->type == OB_ARMATURE) { if (ob->type == OB_ARMATURE) {
arm = ob->data; arm = ob->data;
if (arm && ob->pose && arm->act_bone) { if (arm && ob->pose && arm->act_bone) {
BLI_strncpy( BLI_strncpy(ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone));
} }
} }
@@ -591,7 +590,6 @@ static void object_blend_write(BlendWriter *writer, ID *id, const void *id_addre
BKE_previewimg_blend_write(writer, ob->preview); BKE_previewimg_blend_write(writer, ob->preview);
} }
}
/* XXX deprecated - old animation system */ /* XXX deprecated - old animation system */
static void direct_link_nlastrips(BlendDataReader *reader, ListBase *strips) static void direct_link_nlastrips(BlendDataReader *reader, ListBase *strips)

View File

@@ -108,7 +108,7 @@ static void palette_free_data(ID *id)
static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Palette *palette = (Palette *)id; Palette *palette = (Palette *)id;
if (palette->id.us > 0 || BLO_write_is_undo(writer)) {
PaletteColor *color; PaletteColor *color;
BLO_write_id_struct(writer, Palette, id_address, &palette->id); BLO_write_id_struct(writer, Palette, id_address, &palette->id);
BKE_id_blend_write(writer, &palette->id); BKE_id_blend_write(writer, &palette->id);
@@ -117,7 +117,6 @@ static void palette_blend_write(BlendWriter *writer, ID *id, const void *id_addr
BLO_write_struct(writer, PaletteColor, color); BLO_write_struct(writer, PaletteColor, color);
} }
} }
}
static void palette_blend_read_data(BlendDataReader *reader, ID *id) static void palette_blend_read_data(BlendDataReader *reader, ID *id)
{ {
@@ -187,13 +186,12 @@ static void paint_curve_free_data(ID *id)
static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void paint_curve_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
PaintCurve *pc = (PaintCurve *)id; PaintCurve *pc = (PaintCurve *)id;
if (pc->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id); BLO_write_id_struct(writer, PaintCurve, id_address, &pc->id);
BKE_id_blend_write(writer, &pc->id); BKE_id_blend_write(writer, &pc->id);
BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points); BLO_write_struct_array(writer, PaintCurvePoint, pc->tot_points, pc->points);
} }
}
static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id) static void paint_curve_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -255,7 +255,7 @@ static void write_boid_state(BlendWriter *writer, BoidState *state)
static void particle_settings_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void particle_settings_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
ParticleSettings *part = (ParticleSettings *)id; ParticleSettings *part = (ParticleSettings *)id;
if (part->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */ /* write LibData */
BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id); BLO_write_id_struct(writer, ParticleSettings, id_address, &part->id);
BKE_id_blend_write(writer, &part->id); BKE_id_blend_write(writer, &part->id);
@@ -311,7 +311,6 @@ static void particle_settings_blend_write(BlendWriter *writer, ID *id, const voi
} }
} }
} }
}
void BKE_particle_partdeflect_blend_read_data(BlendDataReader *UNUSED(reader), PartDeflect *pd) void BKE_particle_partdeflect_blend_read_data(BlendDataReader *UNUSED(reader), PartDeflect *pd)
{ {

View File

@@ -112,7 +112,7 @@ static void pointcloud_foreach_id(ID *id, LibraryForeachIDData *data)
static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
PointCloud *pointcloud = (PointCloud *)id; PointCloud *pointcloud = (PointCloud *)id;
if (pointcloud->id.us > 0 || BLO_write_is_undo(writer)) {
CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *players = nullptr, players_buff[CD_TEMP_CHUNK_SIZE];
CustomData_blend_write_prepare( CustomData_blend_write_prepare(
&pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); &pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
@@ -135,7 +135,6 @@ static void pointcloud_blend_write(BlendWriter *writer, ID *id, const void *id_a
MEM_freeN(players); MEM_freeN(players);
} }
} }
}
static void pointcloud_blend_read_data(BlendDataReader *reader, ID *id) static void pointcloud_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -255,8 +255,7 @@ static void screen_foreach_id(ID *id, LibraryForeachIDData *data)
static void screen_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void screen_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
bScreen *screen = (bScreen *)id; bScreen *screen = (bScreen *)id;
/* Screens are reference counted, only saved if used by a workspace. */
if (screen->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */ /* write LibData */
/* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
BLO_write_struct_at_address_with_filecode(writer, ID_SCRN, bScreen, id_address, screen); BLO_write_struct_at_address_with_filecode(writer, ID_SCRN, bScreen, id_address, screen);
@@ -267,7 +266,6 @@ static void screen_blend_write(BlendWriter *writer, ID *id, const void *id_addre
/* direct data */ /* direct data */
BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen)); BKE_screen_area_map_blend_write(writer, AREAMAP_FROM_SCREEN(screen));
} }
}
/* Cannot use IDTypeInfo callback yet, because of the return value. */ /* Cannot use IDTypeInfo callback yet, because of the return value. */
bool BKE_screen_blend_read_data(BlendDataReader *reader, bScreen *screen) bool BKE_screen_blend_read_data(BlendDataReader *reader, bScreen *screen)

View File

@@ -114,7 +114,7 @@ static void simulation_foreach_id(ID *id, LibraryForeachIDData *data)
static void simulation_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void simulation_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Simulation *simulation = (Simulation *)id; Simulation *simulation = (Simulation *)id;
if (simulation->id.us > 0 || BLO_write_is_undo(writer)) {
BLO_write_id_struct(writer, Simulation, id_address, &simulation->id); BLO_write_id_struct(writer, Simulation, id_address, &simulation->id);
BKE_id_blend_write(writer, &simulation->id); BKE_id_blend_write(writer, &simulation->id);
@@ -128,7 +128,6 @@ static void simulation_blend_write(BlendWriter *writer, ID *id, const void *id_a
ntreeBlendWrite(writer, simulation->nodetree); ntreeBlendWrite(writer, simulation->nodetree);
} }
} }
}
static void simulation_blend_read_data(BlendDataReader *reader, ID *id) static void simulation_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -137,7 +137,7 @@ static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_addres
{ {
bSound *sound = (bSound *)id; bSound *sound = (bSound *)id;
const bool is_undo = BLO_write_is_undo(writer); const bool is_undo = BLO_write_is_undo(writer);
if (sound->id.us > 0 || is_undo) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
sound->tags = 0; sound->tags = 0;
sound->handle = NULL; sound->handle = NULL;
@@ -155,7 +155,6 @@ static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BKE_packedfile_blend_write(writer, sound->packedfile); BKE_packedfile_blend_write(writer, sound->packedfile);
} }
}
static void sound_blend_read_data(BlendDataReader *reader, ID *id) static void sound_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -56,7 +56,7 @@ static void speaker_foreach_id(ID *id, LibraryForeachIDData *data)
static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Speaker *spk = (Speaker *)id; Speaker *spk = (Speaker *)id;
if (spk->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */ /* write LibData */
BLO_write_id_struct(writer, Speaker, id_address, &spk->id); BLO_write_id_struct(writer, Speaker, id_address, &spk->id);
BKE_id_blend_write(writer, &spk->id); BKE_id_blend_write(writer, &spk->id);
@@ -65,7 +65,6 @@ static void speaker_blend_write(BlendWriter *writer, ID *id, const void *id_addr
BKE_animdata_blend_write(writer, spk->adt); BKE_animdata_blend_write(writer, spk->adt);
} }
} }
}
static void speaker_blend_read_data(BlendDataReader *reader, ID *id) static void speaker_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -171,9 +171,6 @@ static void text_free_data(ID *id)
static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void text_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
if (id->us < 1 && !BLO_write_is_undo(writer)) {
return;
}
Text *text = (Text *)id; Text *text = (Text *)id;
/* NOTE: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */ /* NOTE: we are clearing local temp data here, *not* the flag in the actual 'real' ID. */

View File

@@ -150,7 +150,7 @@ static void texture_foreach_id(ID *id, LibraryForeachIDData *data)
static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
Tex *tex = (Tex *)id; Tex *tex = (Tex *)id;
if (tex->id.us > 0 || BLO_write_is_undo(writer)) {
/* write LibData */ /* write LibData */
BLO_write_id_struct(writer, Tex, id_address, &tex->id); BLO_write_id_struct(writer, Tex, id_address, &tex->id);
BKE_id_blend_write(writer, &tex->id); BKE_id_blend_write(writer, &tex->id);
@@ -172,7 +172,6 @@ static void texture_blend_write(BlendWriter *writer, ID *id, const void *id_addr
BKE_previewimg_blend_write(writer, tex->preview); BKE_previewimg_blend_write(writer, tex->preview);
} }
}
static void texture_blend_read_data(BlendDataReader *reader, ID *id) static void texture_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -578,7 +578,7 @@ static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_addre
{ {
Volume *volume = (Volume *)id; Volume *volume = (Volume *)id;
const bool is_undo = BLO_write_is_undo(writer); const bool is_undo = BLO_write_is_undo(writer);
if (volume->id.us > 0 || is_undo) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
volume->runtime.grids = nullptr; volume->runtime.grids = nullptr;
@@ -599,7 +599,6 @@ static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_addre
BKE_packedfile_blend_write(writer, volume->packedfile); BKE_packedfile_blend_write(writer, volume->packedfile);
} }
}
static void volume_blend_read_data(BlendDataReader *reader, ID *id) static void volume_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -138,7 +138,7 @@ static void world_foreach_id(ID *id, LibraryForeachIDData *data)
static void world_blend_write(BlendWriter *writer, ID *id, const void *id_address) static void world_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{ {
World *wrld = (World *)id; World *wrld = (World *)id;
if (wrld->id.us > 0 || BLO_write_is_undo(writer)) {
/* Clean up, important in undo case to reduce false detection of changed datablocks. */ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
BLI_listbase_clear(&wrld->gpumaterial); BLI_listbase_clear(&wrld->gpumaterial);
@@ -158,7 +158,6 @@ static void world_blend_write(BlendWriter *writer, ID *id, const void *id_addres
BKE_previewimg_blend_write(writer, wrld->preview); BKE_previewimg_blend_write(writer, wrld->preview);
} }
}
static void world_blend_read_data(BlendDataReader *reader, ID *id) static void world_blend_read_data(BlendDataReader *reader, ID *id)
{ {

View File

@@ -982,6 +982,14 @@ static bool write_file_handle(Main *mainvar,
BLI_assert( BLI_assert(
(id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0); (id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
/* We only write unused IDs in undo case.
* NOTE: All Scenes, WindowManagers and WorkSpaces should always be written to disk, so
* their usercount should never be NULL currently. */
if (id->us == 0 && !wd->use_memfile) {
BLI_assert(!ELEM(GS(id->name), ID_SCE, ID_WM, ID_WS));
continue;
}
const bool do_override = !ELEM(override_storage, NULL, bmain) && const bool do_override = !ELEM(override_storage, NULL, bmain) &&
ID_IS_OVERRIDE_LIBRARY_REAL(id); ID_IS_OVERRIDE_LIBRARY_REAL(id);