From 8e9b6daa8ea5d47fad5e9ec4e8a75c2df7f9b2dc Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 10 May 2013 15:10:54 +0000 Subject: Fix for recent bugfix with anisotropic node crash, could do invalid memory access. --- intern/cycles/render/graph.cpp | 13 +++++++------ intern/cycles/render/graph.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'intern/cycles') diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index f081e2db7af..6f8082487d4 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -135,6 +135,7 @@ void ShaderNode::attributes(AttributeRequestSet *attributes) ShaderGraph::ShaderGraph() { finalized = false; + num_node_ids = 0; add(new OutputNode()); } @@ -147,7 +148,7 @@ ShaderGraph::~ShaderGraph() ShaderNode *ShaderGraph::add(ShaderNode *node) { assert(!finalized); - node->id = nodes.size(); + node->id = num_node_ids++; nodes.push_back(node); return node; } @@ -314,7 +315,7 @@ void ShaderGraph::copy_nodes(set& nodes, map removed(nodes.size(), false); + vector removed(num_node_ids, false); bool any_node_removed = false; /* find and unlink proxy nodes */ @@ -459,11 +460,9 @@ void ShaderGraph::clean() * nodes that don't feed into the output. how cycles are broken is * undefined, they are invalid input, the important thing is to not crash */ - vector visited(nodes.size(), false); - vector on_stack(nodes.size(), false); + vector visited(num_node_ids, false); + vector on_stack(num_node_ids, false); - list newnodes; - /* break cycles */ break_cycles(output(), visited, on_stack); @@ -482,6 +481,8 @@ void ShaderGraph::clean() } /* remove unused nodes */ + list newnodes; + foreach(ShaderNode *node, nodes) { if(visited[node->id]) newnodes.push_back(node); diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h index 8e91a9ddc07..5c4a44af3fc 100644 --- a/intern/cycles/render/graph.h +++ b/intern/cycles/render/graph.h @@ -226,6 +226,7 @@ public: class ShaderGraph { public: list nodes; + size_t num_node_ids; bool finalized; ShaderGraph(); -- cgit v1.2.3