[Bf-blender-cvs] [0f1f7517857] master: Fix T74525: Fluid caches overwrite each other by default

Jacques Lucke noreply at git.blender.org
Tue Mar 10 17:35:07 CET 2020


Commit: 0f1f75178571d9e2644f3b4dd697a5c876bf3ea2
Author: Jacques Lucke
Date:   Tue Mar 10 17:32:38 2020 +0100
Branches: master
https://developer.blender.org/rB0f1f75178571d9e2644f3b4dd697a5c876bf3ea2

Fix T74525: Fluid caches overwrite each other by default

Reviewers: sebbas

Differential Revision: https://developer.blender.org/D7093

===================================================================

M	source/blender/blenkernel/BKE_fluid.h
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/editors/physics/physics_fluid.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_fluid.h b/source/blender/blenkernel/BKE_fluid.h
index 50ff360984c..08bc20c60b5 100644
--- a/source/blender/blenkernel/BKE_fluid.h
+++ b/source/blender/blenkernel/BKE_fluid.h
@@ -62,6 +62,7 @@ void BKE_fluid_reallocate_copy_fluid(struct FluidDomainSettings *mds,
                                      int o_shift[3],
                                      int n_shift[3]);
 void BKE_fluid_cache_free(struct FluidDomainSettings *mds, struct Object *ob, int cache_map);
+void BKE_fluid_cache_new_name_for_current_session(int maxlen, char *r_name);
 
 float BKE_fluid_get_velocity_at(struct Object *ob, float position[3], float velocity[3]);
 int BKE_fluid_get_data_flags(struct FluidDomainSettings *mds);
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index f638211dded..03c9cc7d151 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -26,6 +26,7 @@
 #include "BLI_listbase.h"
 
 #include "BLI_fileops.h"
+#include "BLI_hash.h"
 #include "BLI_math.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
@@ -4810,9 +4811,10 @@ void BKE_fluid_modifier_create_type_data(struct FluidModifierData *mmd)
     mmd->domain->cache_particle_format = FLUID_DOMAIN_FILE_UNI;
     mmd->domain->cache_noise_format = FLUID_DOMAIN_FILE_UNI;
 #endif
-    modifier_path_init(mmd->domain->cache_directory,
-                       sizeof(mmd->domain->cache_directory),
-                       FLUID_DOMAIN_DIR_DEFAULT);
+    char cache_name[64];
+    BKE_fluid_cache_new_name_for_current_session(sizeof(cache_name), cache_name);
+    modifier_path_init(
+        mmd->domain->cache_directory, sizeof(mmd->domain->cache_directory), cache_name);
 
     /* time options */
     mmd->domain->time_scale = 1.0;
@@ -5148,4 +5150,11 @@ void BKE_fluid_modifier_copy(const struct FluidModifierData *mmd,
   }
 }
 
+void BKE_fluid_cache_new_name_for_current_session(int maxlen, char *r_name)
+{
+  static int counter = 1;
+  BLI_snprintf(r_name, maxlen, FLUID_DOMAIN_DIR_DEFAULT "_%x", BLI_hash_int(counter));
+  counter++;
+}
+
 /** \} */
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index c4812d373ab..147c765143e 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -189,8 +189,9 @@ static bool fluid_validatepaths(FluidJob *job, ReportList *reports)
 
   /* We do not accept empty paths, they can end in random places silently, see T51176. */
   if (mds->cache_directory[0] == '\0') {
-    modifier_path_init(
-        mds->cache_directory, sizeof(mds->cache_directory), FLUID_DOMAIN_DIR_DEFAULT);
+    char cache_name[64];
+    BKE_fluid_cache_new_name_for_current_session(sizeof(cache_name), cache_name);
+    modifier_path_init(mds->cache_directory, sizeof(mds->cache_directory), cache_name);
     BKE_reportf(reports,
                 RPT_WARNING,
                 "Fluid: Empty cache path, reset to default '%s'",
@@ -206,8 +207,9 @@ static bool fluid_validatepaths(FluidJob *job, ReportList *reports)
   /* We change path to some presumably valid default value, but do not allow bake process to
    * continue, this gives user chance to set manually another path. */
   if (!dir_exists) {
-    modifier_path_init(
-        mds->cache_directory, sizeof(mds->cache_directory), FLUID_DOMAIN_DIR_DEFAULT);
+    char cache_name[64];
+    BKE_fluid_cache_new_name_for_current_session(sizeof(cache_name), cache_name);
+    modifier_path_init(mds->cache_directory, sizeof(mds->cache_directory), cache_name);
 
     BKE_reportf(reports,
                 RPT_ERROR,



More information about the Bf-blender-cvs mailing list