UI: mitigate problem where remesh could accidentally hang/crash

Having a small voxel size meant typing in zero would clamp the
voxel size to a small number which was often small enough to hang
calculating large voxels which would eventually fail to allocate
memory & crash.

Instead, allow a zero value but bypass calculation.

See #130526.
This commit is contained in:
Campbell Barton 2025-01-22 19:46:16 +11:00
parent acf270b216
commit 6c05859b12
2 changed files with 14 additions and 2 deletions

View file

@ -6350,9 +6350,11 @@ static void rna_def_modifier_remesh(BlenderRNA *brna)
"edges closer to the input");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
/* NOTE: allow zero (which skips computation), to avoid zero clamping
* to a small value which is likely to run out of memory, see: #130526. */
prop = RNA_def_property(srna, "voxel_size", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, nullptr, "voxel_size");
RNA_def_property_range(prop, 0.0001f, FLT_MAX);
RNA_def_property_range(prop, 0.0f, FLT_MAX);
RNA_def_property_ui_range(prop, 0.0001, 2, 0.1, 3);
RNA_def_property_ui_scale_type(prop, PROP_SCALE_LOG);
RNA_def_property_ui_text(prop,
@ -8172,6 +8174,8 @@ static void rna_def_modifier_mesh_to_volume(BlenderRNA *brna)
prop, "Resolution Mode", "Mode for how the desired voxel size is specified");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
/* NOTE: allow zero (which skips computation), to avoid zero clamping
* to a small value which is likely to run out of memory, see: #130526. */
prop = RNA_def_property(srna, "voxel_size", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(
prop, "Voxel Size", "Smaller values result in a higher resolution output");
@ -8336,6 +8340,8 @@ static void rna_def_modifier_volume_to_mesh(BlenderRNA *brna)
prop, "Resolution Mode", "Mode for how the desired voxel size is specified");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
/* NOTE: allow zero (which skips computation), to avoid zero clamping
* to a small value which is likely to run out of memory, see: #130526. */
prop = RNA_def_property(srna, "voxel_size", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(
prop, "Voxel Size", "Smaller values result in a higher resolution output");

View file

@ -127,7 +127,7 @@ static void dualcon_add_quad(void *output_v, const int vert_indices[4])
output->curface++;
}
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext * /*ctx*/, Mesh *mesh)
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
using namespace blender;
RemeshModifierData *rmd;
@ -142,6 +142,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext * /*ctx*/,
if (rmd->mode == MOD_REMESH_VOXEL) {
/* OpenVDB modes. */
if (rmd->voxel_size == 0.0f) {
BKE_modifier_set_error(ctx->object, md, "Zero voxel size cannot be solved");
return nullptr;
}
result = BKE_mesh_remesh_voxel(mesh, rmd->voxel_size, rmd->adaptivity, 0.0f);
@ -150,6 +151,11 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext * /*ctx*/,
}
}
else {
if (rmd->scale == 0.0f) {
BKE_modifier_set_error(ctx->object, md, "Zero scale cannot be solved");
return nullptr;
}
/* Dualcon modes. */
init_dualcon_mesh(&input, mesh);