Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-08-07 14:04:31 +0300
committerJulian Eisel <julian@blender.org>2020-08-07 14:04:31 +0300
commit0d2d4a6d4a75ac38c41f872c88255eab70e88ab7 (patch)
treeb7a7518af86dddba48e05a98b3c2be55e8804721 /source/blender/blenloader/intern/readfile.c
parent9b416c66fb714bdfd15a481489dbf650d0f389ea (diff)
parentcfc6f9eb18e701f5be601b95c45004e8cf7fbc81 (diff)
Merge branch 'master' into temp-ui-button-type-refactortemp-ui-button-type-refactor
Diffstat (limited to 'source/blender/blenloader/intern/readfile.c')
-rw-r--r--source/blender/blenloader/intern/readfile.c427
1 files changed, 78 insertions, 349 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 5a2b8da6ef9..435c96711bd 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1613,21 +1613,6 @@ void blo_filedata_free(FileData *fd)
if (fd->globmap) {
oldnewmap_free(fd->globmap);
}
- if (fd->imamap) {
- oldnewmap_free(fd->imamap);
- }
- if (fd->movieclipmap) {
- oldnewmap_free(fd->movieclipmap);
- }
- if (fd->scenemap) {
- oldnewmap_free(fd->scenemap);
- }
- if (fd->soundmap) {
- oldnewmap_free(fd->soundmap);
- }
- if (fd->volumemap) {
- oldnewmap_free(fd->volumemap);
- }
if (fd->packedmap) {
oldnewmap_free(fd->packedmap);
}
@@ -1804,51 +1789,6 @@ static void *newglobadr(FileData *fd, const void *adr)
return oldnewmap_lookup_and_inc(fd->globmap, adr, true);
}
-/* used to restore image data after undo */
-static void *newimaadr(FileData *fd, const void *adr)
-{
- if (fd->imamap && adr) {
- return oldnewmap_lookup_and_inc(fd->imamap, adr, true);
- }
- return NULL;
-}
-
-/* used to restore scene data after undo */
-static void *newsceadr(FileData *fd, const void *adr)
-{
- if (fd->scenemap && adr) {
- return oldnewmap_lookup_and_inc(fd->scenemap, adr, true);
- }
- return NULL;
-}
-
-/* used to restore movie clip data after undo */
-static void *newmclipadr(FileData *fd, const void *adr)
-{
- if (fd->movieclipmap && adr) {
- return oldnewmap_lookup_and_inc(fd->movieclipmap, adr, true);
- }
- return NULL;
-}
-
-/* used to restore sound data after undo */
-static void *newsoundadr(FileData *fd, const void *adr)
-{
- if (fd->soundmap && adr) {
- return oldnewmap_lookup_and_inc(fd->soundmap, adr, true);
- }
- return NULL;
-}
-
-/* used to restore volume data after undo */
-static void *newvolumeadr(FileData *fd, const void *adr)
-{
- if (fd->volumemap && adr) {
- return oldnewmap_lookup_and_inc(fd->volumemap, adr, true);
- }
- return NULL;
-}
-
/* used to restore packed data after undo */
static void *newpackedadr(FileData *fd, const void *adr)
{
@@ -1926,219 +1866,6 @@ void blo_clear_proxy_pointers_from_lib(Main *oldmain)
}
}
-void blo_make_scene_pointer_map(FileData *fd, Main *oldmain)
-{
- Scene *sce = oldmain->scenes.first;
-
- fd->scenemap = oldnewmap_new();
-
- for (; sce; sce = sce->id.next) {
- if (sce->eevee.light_cache_data) {
- struct LightCache *light_cache = sce->eevee.light_cache_data;
- oldnewmap_insert(fd->scenemap, light_cache, light_cache, 0);
- }
- }
-}
-
-void blo_end_scene_pointer_map(FileData *fd, Main *oldmain)
-{
- OldNew *entry = fd->scenemap->entries;
- Scene *sce = oldmain->scenes.first;
- int i;
-
- /* used entries were restored, so we put them to zero */
- for (i = 0; i < fd->scenemap->nentries; i++, entry++) {
- if (entry->nr > 0) {
- entry->newp = NULL;
- }
- }
-
- for (; sce; sce = sce->id.next) {
- sce->eevee.light_cache_data = newsceadr(fd, sce->eevee.light_cache_data);
- }
-}
-
-void blo_make_image_pointer_map(FileData *fd, Main *oldmain)
-{
- Scene *sce = oldmain->scenes.first;
- fd->imamap = oldnewmap_new();
-
- for (; sce; sce = sce->id.next) {
- if (sce->nodetree && sce->nodetree->previews) {
- bNodeInstanceHashIterator iter;
- NODE_INSTANCE_HASH_ITER (iter, sce->nodetree->previews) {
- bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter);
- oldnewmap_insert(fd->imamap, preview, preview, 0);
- }
- }
- }
-}
-
-/* set old main image ibufs to zero if it has been restored */
-/* this works because freeing old main only happens after this call */
-void blo_end_image_pointer_map(FileData *fd, Main *oldmain)
-{
- OldNew *entry = fd->imamap->entries;
- Scene *sce = oldmain->scenes.first;
- int i;
-
- /* used entries were restored, so we put them to zero */
- for (i = 0; i < fd->imamap->nentries; i++, entry++) {
- if (entry->nr > 0) {
- entry->newp = NULL;
- }
- }
-
- for (; sce; sce = sce->id.next) {
- if (sce->nodetree && sce->nodetree->previews) {
- bNodeInstanceHash *new_previews = BKE_node_instance_hash_new("node previews");
- bNodeInstanceHashIterator iter;
-
- /* reconstruct the preview hash, only using remaining pointers */
- NODE_INSTANCE_HASH_ITER (iter, sce->nodetree->previews) {
- bNodePreview *preview = BKE_node_instance_hash_iterator_get_value(&iter);
- if (preview) {
- bNodePreview *new_preview = newimaadr(fd, preview);
- if (new_preview) {
- bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter);
- BKE_node_instance_hash_insert(new_previews, key, new_preview);
- }
- }
- }
- BKE_node_instance_hash_free(sce->nodetree->previews, NULL);
- sce->nodetree->previews = new_previews;
- }
- }
-}
-
-void blo_make_movieclip_pointer_map(FileData *fd, Main *oldmain)
-{
- MovieClip *clip = oldmain->movieclips.first;
- Scene *sce = oldmain->scenes.first;
-
- fd->movieclipmap = oldnewmap_new();
-
- for (; clip; clip = clip->id.next) {
- if (clip->cache) {
- oldnewmap_insert(fd->movieclipmap, clip->cache, clip->cache, 0);
- }
-
- if (clip->tracking.camera.intrinsics) {
- oldnewmap_insert(
- fd->movieclipmap, clip->tracking.camera.intrinsics, clip->tracking.camera.intrinsics, 0);
- }
- }
-
- for (; sce; sce = sce->id.next) {
- if (sce->nodetree) {
- bNode *node;
- for (node = sce->nodetree->nodes.first; node; node = node->next) {
- if (node->type == CMP_NODE_MOVIEDISTORTION) {
- oldnewmap_insert(fd->movieclipmap, node->storage, node->storage, 0);
- }
- }
- }
- }
-}
-
-/* set old main movie clips caches to zero if it has been restored */
-/* this works because freeing old main only happens after this call */
-void blo_end_movieclip_pointer_map(FileData *fd, Main *oldmain)
-{
- OldNew *entry = fd->movieclipmap->entries;
- MovieClip *clip = oldmain->movieclips.first;
- Scene *sce = oldmain->scenes.first;
- int i;
-
- /* used entries were restored, so we put them to zero */
- for (i = 0; i < fd->movieclipmap->nentries; i++, entry++) {
- if (entry->nr > 0) {
- entry->newp = NULL;
- }
- }
-
- for (; clip; clip = clip->id.next) {
- clip->cache = newmclipadr(fd, clip->cache);
- clip->tracking.camera.intrinsics = newmclipadr(fd, clip->tracking.camera.intrinsics);
- BLI_freelistN(&clip->runtime.gputextures);
- }
-
- for (; sce; sce = sce->id.next) {
- if (sce->nodetree) {
- bNode *node;
- for (node = sce->nodetree->nodes.first; node; node = node->next) {
- if (node->type == CMP_NODE_MOVIEDISTORTION) {
- node->storage = newmclipadr(fd, node->storage);
- }
- }
- }
- }
-}
-
-void blo_make_sound_pointer_map(FileData *fd, Main *oldmain)
-{
- bSound *sound = oldmain->sounds.first;
-
- fd->soundmap = oldnewmap_new();
-
- for (; sound; sound = sound->id.next) {
- if (sound->waveform) {
- oldnewmap_insert(fd->soundmap, sound->waveform, sound->waveform, 0);
- }
- }
-}
-
-/* set old main sound caches to zero if it has been restored */
-/* this works because freeing old main only happens after this call */
-void blo_end_sound_pointer_map(FileData *fd, Main *oldmain)
-{
- OldNew *entry = fd->soundmap->entries;
- bSound *sound = oldmain->sounds.first;
- int i;
-
- /* used entries were restored, so we put them to zero */
- for (i = 0; i < fd->soundmap->nentries; i++, entry++) {
- if (entry->nr > 0) {
- entry->newp = NULL;
- }
- }
-
- for (; sound; sound = sound->id.next) {
- sound->waveform = newsoundadr(fd, sound->waveform);
- }
-}
-
-void blo_make_volume_pointer_map(FileData *fd, Main *oldmain)
-{
- fd->volumemap = oldnewmap_new();
-
- Volume *volume = oldmain->volumes.first;
- for (; volume; volume = volume->id.next) {
- if (volume->runtime.grids) {
- oldnewmap_insert(fd->volumemap, volume->runtime.grids, volume->runtime.grids, 0);
- }
- }
-}
-
-/* set old main volume caches to zero if it has been restored */
-/* this works because freeing old main only happens after this call */
-void blo_end_volume_pointer_map(FileData *fd, Main *oldmain)
-{
- OldNew *entry = fd->volumemap->entries;
- Volume *volume = oldmain->volumes.first;
- int i;
-
- /* used entries were restored, so we put them to zero */
- for (i = 0; i < fd->volumemap->nentries; i++, entry++) {
- if (entry->nr > 0)
- entry->newp = NULL;
- }
-
- for (; volume; volume = volume->id.next) {
- volume->runtime.grids = newvolumeadr(fd, volume->runtime.grids);
- }
-}
-
/* XXX disabled this feature - packed files also belong in temp saves and quit.blend,
* to make restore work. */
@@ -2281,9 +2008,11 @@ typedef struct BLOCacheStorage {
static void blo_cache_storage_entry_register(ID *id,
const IDCacheKey *key,
void **UNUSED(cache_p),
+ eIDTypeInfoCacheCallbackFlags UNUSED(flags),
void *cache_storage_v)
{
BLI_assert(key->id_session_uuid == id->session_uuid);
+ UNUSED_VARS_NDEBUG(id);
BLOCacheStorage *cache_storage = cache_storage_v;
BLI_assert(!BLI_ghash_haskey(cache_storage->cache_map, key));
@@ -2297,12 +2026,18 @@ static void blo_cache_storage_entry_register(ID *id,
static void blo_cache_storage_entry_restore_in_new(ID *UNUSED(id),
const IDCacheKey *key,
void **cache_p,
+ eIDTypeInfoCacheCallbackFlags flags,
void *cache_storage_v)
{
BLOCacheStorage *cache_storage = cache_storage_v;
if (cache_storage == NULL) {
- *cache_p = NULL;
+ /* In non-undo case, only clear the pointer if it is a purely runtime one.
+ * If it may be stored in a persistent way in the .blend file, direct_link code is responsible
+ * to properly deal with it. */
+ if ((flags & IDTYPE_CACHE_CB_FLAGS_PERSISTENT) == 0) {
+ *cache_p = NULL;
+ }
return;
}
@@ -2319,6 +2054,7 @@ static void blo_cache_storage_entry_restore_in_new(ID *UNUSED(id),
static void blo_cache_storage_entry_clear_in_old(ID *UNUSED(id),
const IDCacheKey *key,
void **cache_p,
+ eIDTypeInfoCacheCallbackFlags UNUSED(flags),
void *cache_storage_v)
{
BLOCacheStorage *cache_storage = cache_storage_v;
@@ -2358,7 +2094,7 @@ void blo_cache_storage_init(FileData *fd, Main *bmain)
if (ID_IS_LINKED(id)) {
continue;
}
- type_info->foreach_cache(id, blo_cache_storage_entry_register, fd->cache_storage);
+ BKE_idtype_id_foreach_cache(id, blo_cache_storage_entry_register, fd->cache_storage);
}
FOREACH_MAIN_LISTBASE_ID_END;
}
@@ -2388,7 +2124,7 @@ void blo_cache_storage_old_bmain_clear(FileData *fd, Main *bmain_old)
if (ID_IS_LINKED(id)) {
continue;
}
- type_info->foreach_cache(id, blo_cache_storage_entry_clear_in_old, fd->cache_storage);
+ BKE_idtype_id_foreach_cache(id, blo_cache_storage_entry_clear_in_old, fd->cache_storage);
}
FOREACH_MAIN_LISTBASE_ID_END;
}
@@ -3761,7 +3497,8 @@ static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree)
}
if (node->type == CMP_NODE_MOVIEDISTORTION) {
- node->storage = newmclipadr(reader->fd, node->storage);
+ /* Do nothing, this is runtime cache and hence handled by generic code using
+ * `IDTypeInfo.foreach_cache` callback. */
}
else {
BLO_read_data_address(reader, &node->storage);
@@ -3860,28 +3597,8 @@ static void direct_link_nodetree(BlendDataReader *reader, bNodeTree *ntree)
BLO_read_data_address(reader, &link->tosock);
}
-#if 0
- if (ntree->previews) {
- bNodeInstanceHash* new_previews = BKE_node_instance_hash_new("node previews");
- bNodeInstanceHashIterator iter;
-
- NODE_INSTANCE_HASH_ITER(iter, ntree->previews) {
- bNodePreview* preview = BKE_node_instance_hash_iterator_get_value(&iter);
- if (preview) {
- bNodePreview* new_preview = newimaadr(fd, preview);
- if (new_preview) {
- bNodeInstanceKey key = BKE_node_instance_hash_iterator_get_key(&iter);
- BKE_node_instance_hash_insert(new_previews, key, new_preview);
- }
- }
- }
- BKE_node_instance_hash_free(ntree->previews, NULL);
- ntree->previews = new_previews;
- }
-#else
- /* XXX TODO */
+ /* TODO, should be dealt by new generic cache handling of IDs... */
ntree->previews = NULL;
-#endif
/* type verification is in lib-link */
}
@@ -4445,7 +4162,7 @@ static void direct_link_curve(BlendDataReader *reader, Curve *cu)
direct_link_animdata(reader, cu->adt);
/* Protect against integer overflow vulnerability. */
- CLAMP(cu->len_wchar, 0, INT_MAX - 4);
+ CLAMP(cu->len_char32, 0, INT_MAX - 4);
BLO_read_pointer_array(reader, (void **)&cu->mat);
@@ -4908,7 +4625,6 @@ static void direct_link_particlesystems(BlendDataReader *reader, ListBase *parti
psys->orig_psys = NULL;
psys->batch_cache = NULL;
}
- return;
}
/** \} */
@@ -5429,6 +5145,9 @@ static void direct_link_pose(BlendDataReader *reader, bPose *pose)
pose->chan_array = NULL;
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
+ BKE_pose_channel_runtime_reset(&pchan->runtime);
+ BKE_pose_channel_session_uuid_generate(pchan);
+
pchan->bone = NULL;
BLO_read_data_address(reader, &pchan->parent);
BLO_read_data_address(reader, &pchan->child);
@@ -5454,7 +5173,6 @@ static void direct_link_pose(BlendDataReader *reader, bPose *pose)
CLAMP(pchan->rotmode, ROT_MODE_MIN, ROT_MODE_MAX);
pchan->draw_data = NULL;
- BKE_pose_channel_runtime_reset(&pchan->runtime);
}
pose->ikdata = NULL;
if (pose->ikparam != NULL) {
@@ -5800,7 +5518,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb)
if (gpmd->curve_intensity) {
BKE_curvemapping_blend_read(reader, gpmd->curve_intensity);
/* initialize the curve. Maybe this could be moved to modififer logic */
- BKE_curvemapping_initialize(gpmd->curve_intensity);
+ BKE_curvemapping_init(gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Thick) {
@@ -5809,7 +5527,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb)
BLO_read_data_address(reader, &gpmd->curve_thickness);
if (gpmd->curve_thickness) {
BKE_curvemapping_blend_read(reader, gpmd->curve_thickness);
- BKE_curvemapping_initialize(gpmd->curve_thickness);
+ BKE_curvemapping_init(gpmd->curve_thickness);
}
}
else if (md->type == eGpencilModifierType_Tint) {
@@ -5818,7 +5536,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb)
BLO_read_data_address(reader, &gpmd->curve_intensity);
if (gpmd->curve_intensity) {
BKE_curvemapping_blend_read(reader, gpmd->curve_intensity);
- BKE_curvemapping_initialize(gpmd->curve_intensity);
+ BKE_curvemapping_init(gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Smooth) {
@@ -5826,7 +5544,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb)
BLO_read_data_address(reader, &gpmd->curve_intensity);
if (gpmd->curve_intensity) {
BKE_curvemapping_blend_read(reader, gpmd->curve_intensity);
- BKE_curvemapping_initialize(gpmd->curve_intensity);
+ BKE_curvemapping_init(gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Color) {
@@ -5834,7 +5552,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb)
BLO_read_data_address(reader, &gpmd->curve_intensity);
if (gpmd->curve_intensity) {
BKE_curvemapping_blend_read(reader, gpmd->curve_intensity);
- BKE_curvemapping_initialize(gpmd->curve_intensity);
+ BKE_curvemapping_init(gpmd->curve_intensity);
}
}
else if (md->type == eGpencilModifierType_Opacity) {
@@ -5842,7 +5560,7 @@ static void direct_link_gpencil_modifiers(BlendDataReader *reader, ListBase *lb)
BLO_read_data_address(reader, &gpmd->curve_intensity);
if (gpmd->curve_intensity) {
BKE_curvemapping_blend_read(reader, gpmd->curve_intensity);
- BKE_curvemapping_initialize(gpmd->curve_intensity);
+ BKE_curvemapping_init(gpmd->curve_intensity);
}
}
}
@@ -6314,7 +6032,7 @@ static void direct_link_lightcache_texture(BlendDataReader *reader, LightCacheTe
if (lctex->data) {
BLO_read_data_address(reader, &lctex->data);
- if (BLO_read_requires_endian_switch(reader)) {
+ if (lctex->data && BLO_read_requires_endian_switch(reader)) {
int data_size = lctex->components * lctex->tex_size[0] * lctex->tex_size[1] *
lctex->tex_size[2];
@@ -6326,10 +6044,15 @@ static void direct_link_lightcache_texture(BlendDataReader *reader, LightCacheTe
}
}
}
+
+ if (lctex->data == NULL) {
+ zero_v3_int(lctex->tex_size);
+ }
}
static void direct_link_lightcache(BlendDataReader *reader, LightCache *cache)
{
+ cache->flag &= ~LIGHTCACHE_NOT_USABLE;
direct_link_lightcache_texture(reader, &cache->cube_tx);
direct_link_lightcache_texture(reader, &cache->grid_tx);
@@ -6370,6 +6093,14 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene)
}
for (a = 0, sce_iter = sce; sce_iter->set; sce_iter = sce_iter->set, a++) {
+ /* This runs per library (before each libraries #Main has been joined),
+ * so we can't step into other libraries since `totscene` is only for this library.
+ *
+ * Also, other libraries may not have been linked yet,
+ * while we could check #LIB_TAG_NEED_LINK the library pointer check is sufficient. */
+ if (sce->id.lib != sce_iter->id.lib) {
+ return true;
+ }
if (sce_iter->flag & SCE_READFILE_LIBLINK_NEED_SETSCENE_CHECK) {
return true;
}
@@ -6745,6 +6476,9 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce)
link_recurs_seq(reader, &ed->seqbase);
SEQ_BEGIN (ed, seq) {
+ /* Do as early as possible, so that other parts of reading can rely on valid session UUID. */
+ BKE_sequence_session_uuid_generate(seq);
+
BLO_read_data_address(reader, &seq->seq1);
BLO_read_data_address(reader, &seq->seq2);
BLO_read_data_address(reader, &seq->seq3);
@@ -6943,13 +6677,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce)
}
if (reader->fd->memfile) {
- /* If it's undo try to recover the cache. */
- if (reader->fd->scenemap) {
- sce->eevee.light_cache_data = newsceadr(reader->fd, sce->eevee.light_cache_data);
- }
- else {
- sce->eevee.light_cache_data = NULL;
- }
+ /* If it's undo do nothing here, caches are handled by higher-level generic calling code. */
}
else {
/* else try to read the cache from file. */
@@ -8477,20 +8205,6 @@ static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip)
BLO_read_data_address(reader, &clip->adt);
- if (reader->fd->movieclipmap) {
- clip->cache = newmclipadr(reader->fd, clip->cache);
- }
- else {
- clip->cache = NULL;
- }
-
- if (reader->fd->movieclipmap) {
- clip->tracking.camera.intrinsics = newmclipadr(reader->fd, clip->tracking.camera.intrinsics);
- }
- else {
- clip->tracking.camera.intrinsics = NULL;
- }
-
direct_link_movieTracks(reader, &tracking->tracks);
direct_link_moviePlaneTracks(reader, &tracking->plane_tracks);
direct_link_movieReconstruction(reader, &tracking->reconstruction);
@@ -8502,6 +8216,10 @@ static void direct_link_movieclip(BlendDataReader *reader, MovieClip *clip)
clip->tracking_context = NULL;
clip->tracking.stats = NULL;
+ /* TODO we could store those in undo cache storage as well, and preserve them instead of
+ * re-creating them... */
+ BLI_listbase_clear(&clip->runtime.gputextures);
+
/* Needed for proper versioning, will be NULL for all newer files anyway. */
BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track);
@@ -8910,7 +8628,7 @@ static void direct_link_hair(BlendDataReader *reader, Hair *hair)
BKE_hair_update_customdata_pointers(hair);
/* Materials */
- BLO_read_pointer_array(reader, (void **)hair->mat);
+ BLO_read_pointer_array(reader, (void **)&hair->mat);
}
/** \} */
@@ -8975,8 +8693,11 @@ static void direct_link_volume(BlendDataReader *reader, Volume *volume)
/** \name Read ID: Simulation
* \{ */
-static void lib_link_simulation(BlendLibReader *UNUSED(reader), Simulation *UNUSED(simulation))
+static void lib_link_simulation(BlendLibReader *reader, Simulation *simulation)
{
+ LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
+ BLO_read_id_address(reader, simulation->id.lib, &dependency->id);
+ }
}
static void direct_link_simulation(BlendDataReader *reader, Simulation *simulation)
@@ -8986,16 +8707,15 @@ static void direct_link_simulation(BlendDataReader *reader, Simulation *simulati
BLO_read_list(reader, &simulation->states);
LISTBASE_FOREACH (SimulationState *, state, &simulation->states) {
- switch ((eSimulationStateType)state->type) {
- case SIM_STATE_TYPE_PARTICLES: {
- ParticleSimulationState *particle_state = (ParticleSimulationState *)state;
- direct_link_customdata(reader, &particle_state->attributes, particle_state->tot_particles);
- direct_link_pointcache_list(
- reader, &particle_state->ptcaches, &particle_state->point_cache, 0);
- break;
- };
+ BLO_read_data_address(reader, &state->name);
+ BLO_read_data_address(reader, &state->type);
+ if (STREQ(state->type, SIM_TYPE_NAME_PARTICLE_SIMULATION)) {
+ ParticleSimulationState *particle_state = (ParticleSimulationState *)state;
+ direct_link_customdata(reader, &particle_state->attributes, particle_state->tot_particles);
}
}
+
+ BLO_read_list(reader, &simulation->dependencies);
}
/** \} */
@@ -9268,7 +8988,8 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
/* try to restore (when undoing) or clear ID's cache pointers. */
if (id_type->foreach_cache != NULL) {
- id_type->foreach_cache(id, blo_cache_storage_entry_restore_in_new, reader.fd->cache_storage);
+ BKE_idtype_id_foreach_cache(
+ id, blo_cache_storage_entry_restore_in_new, reader.fd->cache_storage);
}
return success;
@@ -9280,18 +9001,23 @@ static BHead *read_data_into_datamap(FileData *fd, BHead *bhead, const char *all
bhead = blo_bhead_next(fd, bhead);
while (bhead && bhead->code == DATA) {
- void *data;
+ /* The code below is useful for debugging leaks in data read from the blend file.
+ * Without this the messages only tell us what ID-type the memory came from,
+ * eg: `Data from OB len 64`, see #dataname.
+ * With the code below we get the struct-name to help tracking down the leak.
+ * This is kept disabled as the #malloc for the text always leaks memory. */
#if 0
- /* XXX DUMB DEBUGGING OPTION TO GIVE NAMES for guarded malloc errors */
- short* sp = fd->filesdna->structs[bhead->SDNAnr];
- char* tmp = malloc(100);
- allocname = fd->filesdna->types[sp[0]];
- strcpy(tmp, allocname);
- data = read_struct(fd, bhead, tmp);
-#else
- data = read_struct(fd, bhead, allocname);
+ {
+ const short *sp = fd->filesdna->structs[bhead->SDNAnr];
+ allocname = fd->filesdna->types[sp[0]];
+ size_t allocname_size = strlen(allocname) + 1;
+ char *allocname_buf = malloc(allocname_size);
+ memcpy(allocname_buf, allocname, allocname_size);
+ allocname = allocname_buf;
+ }
#endif
+ void *data = read_struct(fd, bhead, allocname);
if (data) {
oldnewmap_insert(fd->datamap, bhead->old, data, 0);
}
@@ -11398,6 +11124,9 @@ static void expand_simulation(BlendExpander *expander, Simulation *simulation)
if (simulation->adt) {
expand_animdata(expander, simulation->adt);
}
+ LISTBASE_FOREACH (SimulationDependency *, dependency, &simulation->dependencies) {
+ BLO_expand(expander, dependency->id);
+ }
}
/**