Depsgraph: Make transitive reduction to work
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Dec 2017 15:16:28 +0000 (16:16 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 20 Dec 2017 15:16:28 +0000 (16:16 +0100)
source/blender/depsgraph/intern/builder/deg_builder_transitive.cc

index b12af21fc8d4582e1e86bb571e961cf32e8614f8..30af0242aeb8e00d1aa8c365e9a5f072e597e1ce 100644 (file)
@@ -84,8 +84,7 @@ void deg_graph_transitive_reduction(Depsgraph *graph)
                foreach (OperationDepsNode *node, graph->operations) {
                        node->done = 0;
                }
-
-               /* mark nodes from which we can reach the target
+               /* Mark nodes from which we can reach the target
                 * start with children, so the target node and direct children are not
                 * flagged.
                 */
@@ -93,25 +92,26 @@ void deg_graph_transitive_reduction(Depsgraph *graph)
                foreach (DepsRelation *rel, target->inlinks) {
                        deg_graph_tag_paths_recursive(rel->from);
                }
-
                /* Remove redundant paths to the target. */
                for (DepsNode::Relations::const_iterator it_rel = target->inlinks.begin();
                     it_rel != target->inlinks.end();
                     )
                {
                        DepsRelation *rel = *it_rel;
-                       /* Increment in advance, so we can safely remove the relation. */
-                       ++it_rel;
-
                        if (rel->from->type == DEG_NODE_TYPE_TIMESOURCE) {
                                /* HACK: time source nodes don't get "done" flag set/cleared. */
                                /* TODO: there will be other types in future, so iterators above
                                 * need modifying.
                                 */
+                               ++it_rel;
                        }
                        else if (rel->from->done & OP_REACHABLE) {
+                               rel->unlink();
                                OBJECT_GUARDED_DELETE(rel, DepsRelation);
                        }
+                       else {
+                               ++it_rel;
+                       }
                }
        }
 }