Fix #108720: allow discovering baked simulation data during rendering

Sometimes the modifier has never been evaluated by an active depsgraph
before it is used for rendering. In this case, the baked data was never
loaded. Now also allow checking for baked data in a non-active depsgraph.
The locking that is in-place already should probably already be enough
to make this thread-safe but maybe that could be made more explicit.
This commit is contained in:
Jacques Lucke
2023-06-14 14:23:13 +02:00
parent 87643d173e
commit 54e303a69c
2 changed files with 16 additions and 17 deletions

View File

@@ -86,11 +86,10 @@ void ModifierSimulationCache::try_discover_bake(const StringRefNull absolute_bak
new_state_at_frame->state.owner_ = this;
states_at_frames_.append(std::move(new_state_at_frame));
}
bdata_sharing_ = std::make_unique<BDataSharing>();
cache_state_ = CacheState::Baked;
}
bdata_sharing_ = std::make_unique<BDataSharing>();
cache_state_ = CacheState::Baked;
}
bool ModifierSimulationCache::has_state_at_frame(const SubFrame &frame) const

View File

@@ -1144,22 +1144,22 @@ static void prepare_simulation_states_for_evaluation(const NodesModifierData &nm
/* This cache may be shared between original and evaluated modifiers. */
blender::bke::sim::ModifierSimulationCache &simulation_cache = *nmd.simulation_cache->ptr;
if (DEG_is_active(ctx.depsgraph)) {
{
/* Try to use baked data. */
const StringRefNull bmain_path = BKE_main_blendfile_path(bmain);
if (simulation_cache.cache_state() != bke::sim::CacheState::Baked && !bmain_path.is_empty())
{
if (!StringRef(nmd.simulation_bake_directory).is_empty()) {
if (const char *base_path = ID_BLEND_PATH(bmain, &ctx.object->id)) {
char absolute_bake_dir[FILE_MAX];
STRNCPY(absolute_bake_dir, nmd.simulation_bake_directory);
BLI_path_abs(absolute_bake_dir, base_path);
simulation_cache.try_discover_bake(absolute_bake_dir);
}
{
/* Try to use baked data. */
const StringRefNull bmain_path = BKE_main_blendfile_path(bmain);
if (simulation_cache.cache_state() != bke::sim::CacheState::Baked && !bmain_path.is_empty()) {
if (!StringRef(nmd.simulation_bake_directory).is_empty()) {
if (const char *base_path = ID_BLEND_PATH(bmain, &ctx.object->id)) {
char absolute_bake_dir[FILE_MAX];
STRNCPY(absolute_bake_dir, nmd.simulation_bake_directory);
BLI_path_abs(absolute_bake_dir, base_path);
simulation_cache.try_discover_bake(absolute_bake_dir);
}
}
}
}
if (DEG_is_active(ctx.depsgraph)) {
{
/* Reset cached data if necessary. */