diff options
author | Hans Goudey <h.goudey@me.com> | 2020-08-12 21:19:05 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-08-12 21:19:05 +0300 |
commit | 31705201dddebf7e3be5c4533b89f380aad1ede1 (patch) | |
tree | 53c8be86b15e9ebd96dd60cad52e6acac8ce2324 /source/blender/blenloader/intern/writefile.c | |
parent | ea4c327c977223922c41c889fa2bd51403409dca (diff) | |
parent | 337b6d075880ea44ff5183804a387dc98673ffb9 (diff) |
Merge branch 'master' into active-fcurve-keyframe
Diffstat (limited to 'source/blender/blenloader/intern/writefile.c')
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 112 |
1 files changed, 66 insertions, 46 deletions
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 4e2b4fef9a0..ed4f997a856 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -152,6 +152,7 @@ #include "MEM_guardedalloc.h" // MEM_freeN #include "BKE_action.h" +#include "BKE_armature.h" #include "BKE_blender_version.h" #include "BKE_bpath.h" #include "BKE_collection.h" @@ -240,9 +241,8 @@ static bool ww_open_none(WriteWrap *ww, const char *filepath) FILE_HANDLE(ww) = file; return true; } - else { - return false; - } + + return false; } static bool ww_close_none(WriteWrap *ww) { @@ -267,9 +267,8 @@ static bool ww_open_zlib(WriteWrap *ww, const char *filepath) FILE_HANDLE(ww) = file; return true; } - else { - return false; - } + + return false; } static bool ww_close_zlib(WriteWrap *ww) { @@ -1582,7 +1581,7 @@ static void write_constraints(BlendWriter *writer, ListBase *conlist) } } -static void write_pose(BlendWriter *writer, bPose *pose) +static void write_pose(BlendWriter *writer, bPose *pose, bArmature *arm) { bPoseChannel *chan; bActionGroup *grp; @@ -1592,6 +1591,8 @@ static void write_pose(BlendWriter *writer, bPose *pose) return; } + BLI_assert(arm != NULL); + /* Write channels */ for (chan = pose->chanbase.first; chan; chan = chan->next) { /* Write ID Properties -- and copy this comment EXACTLY for easy finding @@ -1604,11 +1605,15 @@ static void write_pose(BlendWriter *writer, bPose *pose) write_motionpath(writer, chan->mpath); - /* prevent crashes with autosave, - * when a bone duplicated in editmode has not yet been assigned to its posechannel */ - if (chan->bone) { + /* Prevent crashes with autosave, + * when a bone duplicated in editmode has not yet been assigned to its posechannel. + * Also needed with memundo, in some cases we can store a step before pose has been + * properly rebuilt from previous undo step. */ + Bone *bone = (pose->flag & POSE_RECALC) ? BKE_armature_find_bone_name(arm, chan->name) : + chan->bone; + if (bone != NULL) { /* gets restored on read, for library armatures */ - chan->selectflag = chan->bone->flag & BONE_SELECTED; + chan->selectflag = bone->flag & BONE_SELECTED; } BLO_write_struct(writer, bPoseChannel, chan); @@ -1853,15 +1858,16 @@ static void write_object(BlendWriter *writer, Object *ob, const void *id_address BLO_write_pointer_array(writer, ob->totcol, ob->mat); BLO_write_raw(writer, sizeof(char) * ob->totcol, ob->matbits); + bArmature *arm = NULL; if (ob->type == OB_ARMATURE) { - bArmature *arm = ob->data; + arm = ob->data; if (arm && ob->pose && arm->act_bone) { BLI_strncpy( ob->pose->proxy_act_bone, arm->act_bone->name, sizeof(ob->pose->proxy_act_bone)); } } - write_pose(writer, ob->pose); + write_pose(writer, ob->pose, arm); write_defgroups(writer, &ob->defbase); write_fmaps(writer, &ob->fmaps); write_constraints(writer, &ob->constraints); @@ -2007,7 +2013,7 @@ static void write_curve(BlendWriter *writer, Curve *cu, const void *id_address) if (cu->vfont) { BLO_write_raw(writer, cu->len + 1, cu->str); - BLO_write_struct_array(writer, CharInfo, cu->len_wchar + 1, cu->strinfo); + BLO_write_struct_array(writer, CharInfo, cu->len_char32 + 1, cu->strinfo); BLO_write_struct_array(writer, TextBox, cu->totbox, cu->tb); } else { @@ -2497,7 +2503,12 @@ static void write_lightcache_texture(BlendWriter *writer, LightCacheTexture *tex else if (tex->data_type == LIGHTCACHETEX_UINT) { data_size *= sizeof(uint); } - BLO_write_raw(writer, data_size, tex->data); + + /* FIXME: We can't save more than what 32bit systems can handle. + * The solution would be to split the texture but it is too late for 2.90. (see T78529) */ + if (data_size < INT_MAX) { + BLO_write_raw(writer, data_size, tex->data); + } } } @@ -2835,12 +2846,12 @@ static void write_uilist(BlendWriter *writer, uiList *ui_list) } } -static void write_soops(BlendWriter *writer, SpaceOutliner *so) +static void write_space_outliner(BlendWriter *writer, SpaceOutliner *space_outliner) { - BLI_mempool *ts = so->treestore; + BLI_mempool *ts = space_outliner->treestore; if (ts) { - SpaceOutliner so_flat = *so; + SpaceOutliner space_outliner_flat = *space_outliner; int elems = BLI_mempool_len(ts); /* linearize mempool to array */ @@ -2861,7 +2872,7 @@ static void write_soops(BlendWriter *writer, SpaceOutliner *so) ts_flat.totelem = elems; ts_flat.data = data_addr; - BLO_write_struct(writer, SpaceOutliner, so); + BLO_write_struct(writer, SpaceOutliner, space_outliner); BLO_write_struct_at_address(writer, TreeStore, ts, &ts_flat); BLO_write_struct_array_at_address(writer, TreeStoreElem, elems, data_addr, data); @@ -2869,12 +2880,12 @@ static void write_soops(BlendWriter *writer, SpaceOutliner *so) MEM_freeN(data); } else { - so_flat.treestore = NULL; - BLO_write_struct_at_address(writer, SpaceOutliner, so, &so_flat); + space_outliner_flat.treestore = NULL; + BLO_write_struct_at_address(writer, SpaceOutliner, space_outliner, &space_outliner_flat); } } else { - BLO_write_struct(writer, SpaceOutliner, so); + BLO_write_struct(writer, SpaceOutliner, space_outliner); } } @@ -2950,8 +2961,8 @@ static void write_area_regions(BlendWriter *writer, ScrArea *area) BLO_write_struct(writer, SpaceSeq, sl); } else if (sl->spacetype == SPACE_OUTLINER) { - SpaceOutliner *so = (SpaceOutliner *)sl; - write_soops(writer, so); + SpaceOutliner *space_outliner = (SpaceOutliner *)sl; + write_space_outliner(writer, space_outliner); } else if (sl->spacetype == SPACE_IMAGE) { BLO_write_struct(writer, SpaceImage, sl); @@ -3833,28 +3844,36 @@ static void write_simulation(BlendWriter *writer, Simulation *simulation, const LISTBASE_FOREACH (SimulationState *, state, &simulation->states) { BLO_write_string(writer, state->name); - switch ((eSimulationStateType)state->type) { - case SIM_STATE_TYPE_PARTICLES: { - ParticleSimulationState *particle_state = (ParticleSimulationState *)state; - BLO_write_struct(writer, ParticleSimulationState, particle_state); - - CustomDataLayer *layers = NULL; - CustomDataLayer layers_buff[CD_TEMP_CHUNK_SIZE]; - CustomData_file_write_prepare( - &particle_state->attributes, &layers, layers_buff, ARRAY_SIZE(layers_buff)); - - write_customdata(writer, - &simulation->id, - particle_state->tot_particles, - &particle_state->attributes, - layers, - CD_MASK_ALL); - - write_pointcaches(writer, &particle_state->ptcaches); - break; + BLO_write_string(writer, state->type); + /* TODO: Decentralize this part. */ + if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) { + ParticleSimulationState *particle_state = (ParticleSimulationState *)state; + BLO_write_struct(writer, ParticleSimulationState, particle_state); + + CustomDataLayer *layers = NULL; + CustomDataLayer layers_buff[CD_TEMP_CHUNK_SIZE]; + CustomData_file_write_prepare( + &particle_state->attributes, &layers, layers_buff, ARRAY_SIZE(layers_buff)); + + write_customdata(writer, + &simulation->id, + particle_state->tot_particles, + &particle_state->attributes, + layers, + CD_MASK_ALL); + + if (layers != NULL && layers != layers_buff) { + MEM_freeN(layers); } } + else if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_MESH_EMITTER)) { + ParticleMeshEmitterSimulationState *emitter_state = (ParticleMeshEmitterSimulationState *) + state; + BLO_write_struct(writer, ParticleMeshEmitterSimulationState, emitter_state); + } } + + BLO_write_struct_list(writer, SimulationDependency, &simulation->dependencies); } } @@ -4039,8 +4058,9 @@ static bool write_file_handle(Main *mainvar, * avoid thumbnail detecting changes because of this. */ mywrite_flush(wd); - OverrideLibraryStorage *override_storage = - wd->use_memfile ? NULL : BKE_lib_override_library_operations_store_initialize(); + OverrideLibraryStorage *override_storage = wd->use_memfile ? + NULL : + BKE_lib_override_library_operations_store_init(); #define ID_BUFFER_STATIC_SIZE 8192 /* This outer loop allows to save first data-blocks from real mainvar, @@ -4591,7 +4611,7 @@ void BLO_write_pointer_array(BlendWriter *writer, int size, const void *data_ptr void BLO_write_float3_array(BlendWriter *writer, int size, const float *data_ptr) { - BLO_write_raw(writer, sizeof(float) * 3 * size, data_ptr); + BLO_write_raw(writer, sizeof(float[3]) * size, data_ptr); } /** |