diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-07-10 12:58:01 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-07-10 13:00:58 +0300 |
commit | 25619443bba4b9dda8e6194662683e91be99b247 (patch) | |
tree | 5e4a7ec067f414a5b15959a47acd82334eddbe78 /source/blender/modifiers | |
parent | 0c8452ad99035fa560a1c19a3b4a404bdbbd9ae6 (diff) |
Ocean Modifier: prevent crashing on 'Apply Modifier' button
The 'Apply Modifier' button calls the modifier code on the original
object instead of an evaluated copy, which doesn't have an initialised
Ocean *.
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_ocean.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 5aafd9b1877..12845b27166 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -380,6 +380,7 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes OceanModifierData *omd = (OceanModifierData *) md; int cfra_scene = (int)DEG_get_ctime(ctx->depsgraph); Object *ob = ctx->object; + bool allocated_ocean = false; Mesh *result = NULL; OceanResult ocr; @@ -410,6 +411,12 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes BKE_ocean_simulate_cache(omd->oceancache, cfra_scene); } else { + /* omd->ocean is NULL on an original object (in contrast to an evaluated one). + * We can create a new one, but we have to free it as well once we're done. + * This function is only called on an original object when applying the modifier + * using the 'Apply Modifier' button, and thus it is not called frequently for + * simulation. */ + allocated_ocean |= BKE_ocean_ensure(omd); simulate_ocean_modifier(omd); } @@ -503,6 +510,11 @@ static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mes } } + if (allocated_ocean) { + BKE_ocean_free(omd->ocean); + omd->ocean = NULL; + } + #undef OCEAN_CO return result; |