Fix T59395: Subdivision modifier with quality 1 crashes blender

This is actually a workaround for the crash in OpenSubdiv.
Topology refiner will have a crash when special conditions
are met:

- Refiner is configured to use infinitely sharp patches.
- Refinement happens for the level 1 (which we call Quality 1 on
  Blender side).
- Mesh has non-quad faces.

The workaround is to force refinement to happen to level 2 (or
quality 2 on Blender side) when those conditions are met.

Later on with the next OpenSubdiv update we can remove this
workaround, since there was work done on OpenSubdiv side to
deal better with such configurations.

The modifier will now be somewhat slower, but this will be
compensated with upcoming topology cache enabled by default.

The workaround is done when initializing settings, so the
comparison of topology refiner settings is happening without
any extra workarounds there.
This commit is contained in:
2019-01-21 16:43:30 +01:00
parent fef20d987c
commit d6d101feca
4 changed files with 28 additions and 0 deletions

View File

@@ -194,6 +194,9 @@ void BKE_subdiv_stats_print(const SubdivStats *stats);
/* ================================ SETTINGS ================================ */
void BKE_subdiv_settings_validate_for_mesh(SubdivSettings *settings,
const struct Mesh *mesh);
bool BKE_subdiv_settings_equal(const SubdivSettings *settings_a,
const SubdivSettings *settings_b);

View File

@@ -30,6 +30,7 @@
#include "BKE_subdiv.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "BLI_utildefines.h"
@@ -68,6 +69,28 @@ BKE_subdiv_fvar_interpolation_from_uv_smooth(int uv_smooth)
/* ================================ SETTINGS ================================ */
static bool check_mesh_has_non_quad(const Mesh *mesh)
{
for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) {
const MPoly *poly = &mesh->mpoly[poly_index];
if (poly->totloop != 4) {
return true;
}
}
return false;
}
void BKE_subdiv_settings_validate_for_mesh(SubdivSettings *settings,
const Mesh *mesh)
{
if (settings->level != 1) {
return;
}
if (check_mesh_has_non_quad(mesh)) {
settings->level = 2;
}
}
bool BKE_subdiv_settings_equal(const SubdivSettings *settings_a,
const SubdivSettings *settings_b)
{

View File

@@ -159,6 +159,7 @@ static Mesh *applyModifier(ModifierData *md,
if (subdiv_settings.level == 0) {
return result;
}
BKE_subdiv_settings_validate_for_mesh(&subdiv_settings, mesh);
Subdiv *subdiv = subdiv_descriptor_ensure(mmd, &subdiv_settings, mesh);
if (subdiv == NULL) {
/* Happens on bad topology, ut also on empty input mesh. */

View File

@@ -206,6 +206,7 @@ static Mesh *applyModifier(ModifierData *md,
if (subdiv_settings.level == 0) {
return result;
}
BKE_subdiv_settings_validate_for_mesh(&subdiv_settings, mesh);
Subdiv *subdiv = subdiv_descriptor_ensure(smd, &subdiv_settings, mesh);
if (subdiv == NULL) {
/* Happens on bad topology, but also on empty input mesh. */