From a7c5f4f20657e12b43337e32bc62a876cbbe6292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 28 Dec 2018 18:05:31 +0100 Subject: Fix T57078: Alembic curve import: better check for topology similarity The old code assumed that if the number of curves was the same, the entire set of curves would have the same topology (in other words, it assumed 'same number of curves => same number of vertices for each curve'). I've added a more thorough check that also considers the number of vertices in each curve. This still keeps certain assumptions in place (for example that if the topology is the same, the weights won't change, which is not necessarily true). However, when the assumption doesn't hold, at least now Blender doesn't crash any more. --- source/blender/alembic/intern/abc_curves.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'source/blender/alembic') diff --git a/source/blender/alembic/intern/abc_curves.cc b/source/blender/alembic/intern/abc_curves.cc index f9880eda451..fa5e2214836 100644 --- a/source/blender/alembic/intern/abc_curves.cc +++ b/source/blender/alembic/intern/abc_curves.cc @@ -440,18 +440,32 @@ Mesh *AbcCurveReader::read_mesh(Mesh *existing_mesh, const Int32ArraySamplePtr num_vertices = sample.getCurvesNumVertices(); int vertex_idx = 0; - int curve_idx = 0; + int curve_idx; Curve *curve = static_cast(m_object->data); const int curve_count = BLI_listbase_count(&curve->nurb); + bool same_topology = curve_count == num_vertices->size(); - if (curve_count != num_vertices->size()) { + if (same_topology) { + Nurb *nurbs = static_cast(curve->nurb.first); + for (curve_idx=0; nurbs; nurbs = nurbs->next, ++curve_idx) { + const int num_in_alembic = (*num_vertices)[curve_idx]; + const int num_in_blender = nurbs->pntsu; + + if (num_in_alembic != num_in_blender) { + same_topology = false; + break; + } + } + } + + if (!same_topology) { BKE_nurbList_free(&curve->nurb); read_curve_sample(curve, m_curves_schema, sample_sel); } else { Nurb *nurbs = static_cast(curve->nurb.first); - for (; nurbs; nurbs = nurbs->next, ++curve_idx) { + for (curve_idx=0; nurbs; nurbs = nurbs->next, ++curve_idx) { const int totpoint = (*num_vertices)[curve_idx]; if (nurbs->bp) { -- cgit v1.2.3