diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-24 21:31:09 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-04-24 21:31:09 +0400 |
commit | dbeec2be86db5b4ba440175e59c52ff84eb98462 (patch) | |
tree | 8bedb75ea7937279d318b86f5eecc98f8e03a950 /source/blender/blenkernel | |
parent | 64e28b21ba8472f4fd822b918d6e7d7c1be87dcb (diff) |
Fix #34783: smoke simulation crash when changing frame while preview rendering.
Added a mutex lock for smoke data access. The render was already working with a
copy of the volume data, so it's just a short lock to copy things and should not
block the UI much.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/smoke.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index 009112be2c9..f31a672c664 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -50,6 +50,7 @@ #include "BLI_edgehash.h" #include "BLI_kdtree.h" #include "BLI_kdopbvh.h" +#include "BLI_threads.h" #include "BLI_utildefines.h" #include "BLI_voxel.h" @@ -365,6 +366,9 @@ static void smokeModifier_freeDomain(SmokeModifierData *smd) if (smd->domain->fluid) smoke_free(smd->domain->fluid); + if (smd->domain->fluid_mutex) + BLI_rw_mutex_free(smd->domain->fluid_mutex); + if (smd->domain->wt) smoke_turbulence_free(smd->domain->wt); @@ -436,8 +440,12 @@ void smokeModifier_reset(struct SmokeModifierData *smd) if (smd->domain->fluid) { + BLI_rw_mutex_lock(smd->domain->fluid_mutex, THREAD_LOCK_WRITE); + smoke_free(smd->domain->fluid); smd->domain->fluid = NULL; + + BLI_rw_mutex_unlock(smd->domain->fluid_mutex); } smokeModifier_reset_turbulence(smd); @@ -497,6 +505,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd) smd->domain->ptcaches[1].first = smd->domain->ptcaches[1].last = NULL; /* set some standard values */ smd->domain->fluid = NULL; + smd->domain->fluid_mutex = BLI_rw_mutex_alloc(); smd->domain->wt = NULL; smd->domain->eff_group = NULL; smd->domain->fluid_group = NULL; @@ -2316,8 +2325,15 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object * struct DerivedMesh *smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm) { + /* lock so preview render does not read smoke data while it gets modified */ + if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) + BLI_rw_mutex_lock(smd->domain->fluid_mutex, THREAD_LOCK_WRITE); + smokeModifier_process(smd, scene, ob, dm); + if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) + BLI_rw_mutex_unlock(smd->domain->fluid_mutex); + /* return generated geometry for adaptive domain */ if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain && smd->domain->flags & MOD_SMOKE_ADAPTIVE_DOMAIN && |