From 16b165eed5e929f8f6ea2917fa4cb803e0c1dcc0 Mon Sep 17 00:00:00 2001 From: Chris Want Date: Fri, 6 Jul 2012 16:55:35 +0000 Subject: [PATCH 1/3] Fix for bug 32017. There was some bad recursion introduced recently that caused crashes when a Material node is the same material as the material itself (e.g., if Material.001 has a node with Material.001). This commit attempt to correct this by keeping track of the material at the root of the node tree, and doesn't recurse further if it encounters it again within the nodetree. Joshua, please review! --- source/blender/blenkernel/intern/depsgraph.c | 14 +++++++++----- source/blender/blenkernel/intern/material.c | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 2faa882e3ea..05a2cfee8e6 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -352,10 +352,11 @@ static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma); /* recursive handling for material nodetree drivers */ -static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree) +static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree, Material *rootma) { bNode *n; - + Material *ma; + /* nodetree itself */ if (ntree->adt) { dag_add_driver_relation(ntree->adt, dag, node, 1); @@ -364,10 +365,13 @@ static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode * /* nodetree's nodes... */ for (n = ntree->nodes.first; n; n = n->next) { if (n->id && GS(n->id->name) == ID_MA) { - dag_add_material_driver_relations(dag, node, (Material *)n->id); + ma = (Material *)n->id; + if (ma != rootma) { + dag_add_material_driver_relations(dag, node, ma); + } } else if (n->type == NODE_GROUP && n->id) { - dag_add_material_nodetree_driver_relations(dag, node, (bNodeTree *)n->id); + dag_add_material_nodetree_driver_relations(dag, node, (bNodeTree *)n->id, rootma); } } } @@ -386,7 +390,7 @@ static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Mat /* material's nodetree */ if (ma->nodetree) { - dag_add_material_nodetree_driver_relations(dag, node, ma->nodetree); + dag_add_material_nodetree_driver_relations(dag, node, ma->nodetree, ma); } } diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 23f197155a1..de2b99fcbf9 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1056,10 +1056,11 @@ int material_in_material(Material *parmat, Material *mat) /* ****************** */ /* Update drivers for materials in a nodetree */ -static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime) +static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime, Material *rootma) { bNode *node; - + Material *ma; + /* nodetree itself */ if (ntree->adt && ntree->adt->drivers.first) { BKE_animsys_evaluate_animdata(scene, &ntree->id, ntree->adt, ctime, ADT_RECALC_DRIVERS); @@ -1069,10 +1070,14 @@ static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float c for (node = ntree->nodes.first; node; node = node->next) { if (node->id && GS(node->id->name) == ID_MA) { /* TODO: prevent infinite recursion here... */ - material_drivers_update(scene, (Material *)node->id, ctime); + ma = (Material *)node->id; + if (ma != rootma) { + material_drivers_update(scene, ma, ctime); + } } else if (node->type == NODE_GROUP && node->id) { - material_node_drivers_update(scene, (bNodeTree *)node->id, ctime); + material_node_drivers_update(scene, (bNodeTree *)node->id, + ctime, rootma); } } } @@ -1094,7 +1099,7 @@ void material_drivers_update(Scene *scene, Material *ma, float ctime) /* nodes */ if (ma->nodetree) { - material_node_drivers_update(scene, ma->nodetree, ctime); + material_node_drivers_update(scene, ma->nodetree, ctime, ma); } } From 1a9e7a00f3d11c6c0eed955c7cd45adca9522111 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Jul 2012 19:22:21 +0000 Subject: [PATCH 2/3] style cleanup: var names --- source/blender/bmesh/operators/bmo_hull.c | 35 ++++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c index 82ab49b5c38..f94683c3bc1 100644 --- a/source/blender/bmesh/operators/bmo_hull.c +++ b/source/blender/bmesh/operators/bmo_hull.c @@ -72,23 +72,23 @@ typedef struct HullBoundaryEdge { /*************************** Boundary Edges ***************************/ -static int edge_match(BMVert *e1_0, BMVert *e1_1, BMVert *e2[2]) +static int edge_match(BMVert *e1_v1, BMVert *e1_v2, BMVert *e2[2]) { - return (e1_0 == e2[0] && e1_1 == e2[1]) || - (e1_0 == e2[1] && e1_1 == e2[0]); + return (e1_v1 == e2[0] && e1_v2 == e2[1]) || + (e1_v1 == e2[1] && e1_v2 == e2[0]); } /* Returns true if the edge (e1, e2) is already in edges; that edge is * deleted here as well. if not found just returns 0 */ static int check_for_dup(ListBase *edges, BLI_mempool *pool, - BMVert *e1, BMVert *e2) + BMVert *v1, BMVert *v2) { - HullBoundaryEdge *e, *next; + HullBoundaryEdge *e, *e_next; - for (e = edges->first; e; e = next) { - next = e->next; + for (e = edges->first; e; e = e_next) { + e_next = e->next; - if (edge_match(e1, e2, e->v)) { + if (edge_match(v1, v2, e->v)) { /* remove the interior edge */ BLI_remlink(edges, e); BLI_mempool_free(pool, e); @@ -102,17 +102,17 @@ static int check_for_dup(ListBase *edges, BLI_mempool *pool, static void expand_boundary_edges(ListBase *edges, BLI_mempool *edge_pool, const HullTriangle *t) { - HullBoundaryEdge *new; + HullBoundaryEdge *e_new; int i; /* Insert each triangle edge into the boundary list; if any of * its edges are already in there, remove the edge entirely */ for (i = 0; i < 3; i++) { if (!check_for_dup(edges, edge_pool, t->v[i], t->v[(i + 1) % 3])) { - new = BLI_mempool_calloc(edge_pool); - new->v[0] = t->v[i]; - new->v[1] = t->v[(i + 1) % 3]; - BLI_addtail(edges, new); + e_new = BLI_mempool_calloc(edge_pool); + e_new->v[0] = t->v[i]; + e_new->v[1] = t->v[(i + 1) % 3]; + BLI_addtail(edges, e_new); } } } @@ -179,7 +179,7 @@ static void add_point(BMesh *bm, GHash *hull_triangles, BLI_mempool *hull_pool, BLI_mempool *edge_pool, GHash *outside, BMVert *v) { ListBase edges = {NULL, NULL}; - HullBoundaryEdge *e, *next; + HullBoundaryEdge *e, *e_next; GHashIterator iter; GHASH_ITER (iter, outside) { @@ -198,8 +198,8 @@ static void add_point(BMesh *bm, GHash *hull_triangles, BLI_mempool *hull_pool, } /* Fill hole boundary with triangles to new point */ - for (e = edges.first; e; e = next) { - next = e->next; + for (e = edges.first; e; e = e_next) { + e_next = e->next; hull_add_triangle(bm, hull_triangles, hull_pool, e->v[0], e->v[1], v); BLI_mempool_free(edge_pool, e); } @@ -356,7 +356,8 @@ static void hull_add_tetrahedron(BMesh *bm, GHash *hull_triangles, BLI_mempool * {0, 1, 2}, {0, 2, 3}, {1, 0, 3}, - {2, 1, 3}}; + {2, 1, 3} + }; /* Calculate center */ zero_v3(center); From 2336aadb80f8602f001b2c5b0bcaacf3ad858f83 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Jul 2012 20:16:04 +0000 Subject: [PATCH 3/3] decrease size for convex hull epsilon when checking which side of a face the vertex is on. this doesnt fix all cases but works better then it did. --- source/blender/bmesh/operators/bmo_hull.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c index f94683c3bc1..d4f63ab7557 100644 --- a/source/blender/bmesh/operators/bmo_hull.c +++ b/source/blender/bmesh/operators/bmo_hull.c @@ -38,6 +38,9 @@ #include "bmesh.h" #define HULL_EPSILON_FLT 0.0001f +/* values above 0.0001 cause errors, see below for details, don't increase + * without checking against bug [#32027] */ +#define HULL_EPSILON_DOT_FLT 0.00000001f /* Internal operator flags */ typedef enum { @@ -144,12 +147,16 @@ static int hull_point_tri_side(const HullTriangle *t, const float co[3]) { /* Added epsilon to fix bug [#31941], improves output when some * vertices are nearly coplanar. Might need further tweaking for - * other cases though. */ + * other cases though. + * ... + * Update: epsilon of 0.0001 causes [#32027], use HULL_EPSILON_DOT_FLT + * and give it a much smaller value + * */ float p[3], d; sub_v3_v3v3(p, co, t->v[0]->co); d = dot_v3v3(t->no, p); - if (d < -HULL_EPSILON_FLT) return -1; - else if (d > HULL_EPSILON_FLT) return 1; + if (d < -HULL_EPSILON_DOT_FLT) return -1; + else if (d > HULL_EPSILON_DOT_FLT) return 1; else return 0; }