forked from bartvdbraak/blender
Fix for recent bugfix with anisotropic node crash, could do invalid memory access.
This commit is contained in:
parent
65ed588c8b
commit
8e9b6daa8e
@ -135,6 +135,7 @@ void ShaderNode::attributes(AttributeRequestSet *attributes)
|
|||||||
ShaderGraph::ShaderGraph()
|
ShaderGraph::ShaderGraph()
|
||||||
{
|
{
|
||||||
finalized = false;
|
finalized = false;
|
||||||
|
num_node_ids = 0;
|
||||||
add(new OutputNode());
|
add(new OutputNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +148,7 @@ ShaderGraph::~ShaderGraph()
|
|||||||
ShaderNode *ShaderGraph::add(ShaderNode *node)
|
ShaderNode *ShaderGraph::add(ShaderNode *node)
|
||||||
{
|
{
|
||||||
assert(!finalized);
|
assert(!finalized);
|
||||||
node->id = nodes.size();
|
node->id = num_node_ids++;
|
||||||
nodes.push_back(node);
|
nodes.push_back(node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -314,7 +315,7 @@ void ShaderGraph::copy_nodes(set<ShaderNode*>& nodes, map<ShaderNode*, ShaderNod
|
|||||||
|
|
||||||
void ShaderGraph::remove_unneeded_nodes()
|
void ShaderGraph::remove_unneeded_nodes()
|
||||||
{
|
{
|
||||||
vector<bool> removed(nodes.size(), false);
|
vector<bool> removed(num_node_ids, false);
|
||||||
bool any_node_removed = false;
|
bool any_node_removed = false;
|
||||||
|
|
||||||
/* find and unlink proxy nodes */
|
/* find and unlink proxy nodes */
|
||||||
@ -459,10 +460,8 @@ void ShaderGraph::clean()
|
|||||||
* nodes that don't feed into the output. how cycles are broken is
|
* 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 */
|
* undefined, they are invalid input, the important thing is to not crash */
|
||||||
|
|
||||||
vector<bool> visited(nodes.size(), false);
|
vector<bool> visited(num_node_ids, false);
|
||||||
vector<bool> on_stack(nodes.size(), false);
|
vector<bool> on_stack(num_node_ids, false);
|
||||||
|
|
||||||
list<ShaderNode*> newnodes;
|
|
||||||
|
|
||||||
/* break cycles */
|
/* break cycles */
|
||||||
break_cycles(output(), visited, on_stack);
|
break_cycles(output(), visited, on_stack);
|
||||||
@ -482,6 +481,8 @@ void ShaderGraph::clean()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* remove unused nodes */
|
/* remove unused nodes */
|
||||||
|
list<ShaderNode*> newnodes;
|
||||||
|
|
||||||
foreach(ShaderNode *node, nodes) {
|
foreach(ShaderNode *node, nodes) {
|
||||||
if(visited[node->id])
|
if(visited[node->id])
|
||||||
newnodes.push_back(node);
|
newnodes.push_back(node);
|
||||||
|
@ -226,6 +226,7 @@ public:
|
|||||||
class ShaderGraph {
|
class ShaderGraph {
|
||||||
public:
|
public:
|
||||||
list<ShaderNode*> nodes;
|
list<ShaderNode*> nodes;
|
||||||
|
size_t num_node_ids;
|
||||||
bool finalized;
|
bool finalized;
|
||||||
|
|
||||||
ShaderGraph();
|
ShaderGraph();
|
||||||
|
Loading…
Reference in New Issue
Block a user