Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2021-08-04 10:18:21 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-08-04 11:29:43 +0300
commit218df9941097bf973485ac343c070bdc6641a539 (patch)
treef831265bc737b30a811385b46911eef01b40b4c4 /source/blender/modifiers/intern/MOD_ocean.c
parent3b0fab6dfaa00a6fd476d28c160fcd9219f9a973 (diff)
Modifier: warn if the ocean simulation fails to allocate memory
While most modifies don't handle out of memory cases, ocean simulation could attempt huge allocations: 2048 gb at the maximum resolution. Resolves T83952.
Diffstat (limited to 'source/blender/modifiers/intern/MOD_ocean.c')
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index 8f3206da5be..1c502b94bdb 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -95,8 +95,9 @@ static void initData(ModifierData *md)
BKE_modifier_path_init(omd->cachepath, sizeof(omd->cachepath), "cache_ocean");
omd->ocean = BKE_ocean_add();
- BKE_ocean_init_from_modifier(omd->ocean, omd, omd->viewport_resolution);
- simulate_ocean_modifier(omd);
+ if (BKE_ocean_init_from_modifier(omd->ocean, omd, omd->viewport_resolution)) {
+ simulate_ocean_modifier(omd);
+ }
#else /* WITH_OCEANSIM */
UNUSED_VARS(md);
#endif /* WITH_OCEANSIM */
@@ -132,8 +133,9 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
tomd->oceancache = NULL;
tomd->ocean = BKE_ocean_add();
- BKE_ocean_init_from_modifier(tomd->ocean, tomd, tomd->viewport_resolution);
- simulate_ocean_modifier(tomd);
+ if (BKE_ocean_init_from_modifier(tomd->ocean, tomd, tomd->viewport_resolution)) {
+ simulate_ocean_modifier(tomd);
+ }
#else /* WITH_OCEANSIM */
/* unused */
(void)md;
@@ -323,6 +325,10 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, co
static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
OceanModifierData *omd = (OceanModifierData *)md;
+ if (omd->ocean && !BKE_ocean_is_valid(omd->ocean)) {
+ BKE_modifier_set_error(ctx->object, md, "Failed to allocate memory");
+ return mesh;
+ }
int cfra_scene = (int)DEG_get_ctime(ctx->depsgraph);
Object *ob = ctx->object;
bool allocated_ocean = false;