Fix #161602: Avoid early gas fluid reallocation

The fluid reallocation added in 87d48ea687 was moved before all cache
reads. For gas domains with noise, this cleared the existing solver
state before `BKE_fluid_reallocate_copy_fluid()` could preserve it,
causing smoke and fire to disappear after the emitters stopped.

Limit the early destructive reallocation to liquid mesh and particle
cache reads, which need it before the regular data cache is loaded, and
restore the original reallocation in the regular data-cache path.

Pull Request: https://projects.blender.org/blender/blender/pulls/161623
This commit is contained in:
Tibo Stans 2026-08-04 21:17:48 +02:00 • committed by Hans Goudey
parent 03e41a054c
commit 4afd2ae810

View file

@ -3894,20 +3894,20 @@ static void fluid_modifier_processDomain(FluidModifierData *fmd,
/* Try to read from cache and keep track of read success. */
if (read_cache) {
/* Reallocate fluid object to match cached config before reading mesh/particles. */
if (has_config && manta_needs_realloc(fds->fluid, fmd)) {
BKE_fluid_reallocate_fluid(fds, fds->res, 1);
}
/* Read mesh cache. */
if (with_liquid && with_mesh) {
if (mesh_frame != scene_framenr) {
has_config = manta_read_config(fds->fluid, fmd, mesh_frame);
}
/* Only load the mesh at the resolution it ways originally simulated at.
* The mesh files don't have a header, i.e. the don't store the grid resolution. */
/* The liquid mesh cache is read before the regular data-cache allocation. Ensure the Manta
* instance matches the cached configuration here instead of reallocating all cache types. */
if (has_config && manta_needs_realloc(fds->fluid, fmd)) {
BKE_fluid_reallocate_fluid(fds, fds->res, 1);
}
/* Only load the mesh at the resolution it was originally simulated at.
* The mesh files don't have a header, i.e. they don't store the grid resolution. */
if (!manta_needs_realloc(fds->fluid, fmd)) {
has_mesh = manta_read_mesh(fds->fluid, fmd, mesh_frame);
}
@ -3919,6 +3919,11 @@ static void fluid_modifier_processDomain(FluidModifierData *fmd,
has_config = manta_read_config(fds->fluid, fmd, particles_frame);
}
/* The liquid particle cache is also read before the regular data-cache allocation. */
if (has_config && manta_needs_realloc(fds->fluid, fmd)) {
BKE_fluid_reallocate_fluid(fds, fds->res, 1);
}
read_partial = !baking_data && !baking_particles && next_particles;
read_all = !read_partial && with_resumable_cache;
has_particles = manta_read_particles(fds->fluid, fmd, particles_frame, read_all);
@ -3956,6 +3961,13 @@ static void fluid_modifier_processDomain(FluidModifierData *fmd,
has_config = manta_read_config(fds->fluid, fmd, data_frame);
}
if (with_smoke || with_liquid) {
/* Read config and realloc fluid object if needed. */
if (has_config && manta_needs_realloc(fds->fluid, fmd)) {
BKE_fluid_reallocate_fluid(fds, fds->res, 1);
}
}
read_partial = !baking_data && !baking_particles && !baking_mesh && next_data &&
!grid_display;
read_all = !read_partial && with_resumable_cache;