Geometry Nodes: Add error message when applying modifier with no mesh

If the resulting geometry from applying a geometry nodes modifier
contains no mesh, give an error message. This gives people something to
search and makes the behavior more purposeful.

Also remove the `modifyMesh` implementation from the geometry nodes
modifier, since it isn't necessary anymore. And remove the existing
"Modifier returned error, skipping apply" message which was cryptic
and redundant if applying returns an actual error message.

Resolves T103229

Differential Revision: https://developer.blender.org/D16782
This commit is contained in:
Hans Goudey 2022-12-15 14:05:01 -06:00
parent ae886596a0
commit b1494bcea7
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by issue #103301, Crash with Blender Studio's stretching visualization file
Referenced by issue #103229, Object disappears when modifier GN is applied
2 changed files with 22 additions and 21 deletions

View File

@ -694,7 +694,8 @@ static Mesh *create_applied_mesh_for_modifier(Depsgraph *depsgraph,
Object *ob_eval,
ModifierData *md_eval,
const bool use_virtual_modifiers,
const bool build_shapekey_layers)
const bool build_shapekey_layers,
ReportList *reports)
{
Mesh *me = ob_eval->runtime.data_orig ? reinterpret_cast<Mesh *>(ob_eval->runtime.data_orig) :
reinterpret_cast<Mesh *>(ob_eval->data);
@ -766,9 +767,21 @@ static Mesh *create_applied_mesh_for_modifier(Depsgraph *depsgraph,
add_shapekey_layers(*mesh_temp, *me);
}
result = mti->modifyMesh(md_eval, &mectx, mesh_temp);
if (mesh_temp != result) {
BKE_id_free(nullptr, mesh_temp);
if (mti->modifyGeometrySet) {
GeometrySet geometry_set = GeometrySet::create_with_mesh(mesh_temp,
GeometryOwnershipType::Owned);
mti->modifyGeometrySet(md_eval, &mectx, &geometry_set);
if (!geometry_set.has_mesh()) {
BKE_report(reports, RPT_ERROR, "Evaluated geometry from modifier does not contain a mesh");
return nullptr;
}
result = geometry_set.get_component_for_write<MeshComponent>().release();
}
else {
result = mti->modifyMesh(md_eval, &mectx, mesh_temp);
if (mesh_temp != result) {
BKE_id_free(nullptr, mesh_temp);
}
}
}
@ -817,7 +830,8 @@ static bool modifier_apply_shape(Main *bmain,
DEG_get_evaluated_object(depsgraph, ob),
md_eval,
true,
false);
false,
reports);
if (!mesh_applied) {
BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
return false;
@ -883,9 +897,9 @@ static bool modifier_apply_obdata(
/* It's important not to apply virtual modifiers (e.g. shape-keys) because they're kept,
* causing them to be applied twice, see: T97758. */
false,
true);
true,
reports);
if (!mesh_applied) {
BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply");
return false;
}

View File

@ -1309,19 +1309,6 @@ static void modifyGeometry(ModifierData *md,
}
}
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
GeometrySet geometry_set = GeometrySet::create_with_mesh(mesh, GeometryOwnershipType::Editable);
modifyGeometry(md, ctx, geometry_set);
Mesh *new_mesh = geometry_set.get_component_for_write<MeshComponent>().release();
if (new_mesh == nullptr) {
return BKE_mesh_new_nomain(0, 0, 0, 0, 0);
}
return new_mesh;
}
static void modifyGeometrySet(ModifierData *md,
const ModifierEvalContext *ctx,
GeometrySet *geometry_set)
@ -1882,7 +1869,7 @@ ModifierTypeInfo modifierType_Nodes = {
/* deformMatrices */ nullptr,
/* deformVertsEM */ nullptr,
/* deformMatricesEM */ nullptr,
/* modifyMesh */ modifyMesh,
/* modifyMesh */ nullptr,
/* modifyGeometrySet */ modifyGeometrySet,
/* initData */ initData,