Tomato Cycles: fix for reading freed memory
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 19 Aug 2012 12:07:28 +0000 (12:07 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 19 Aug 2012 12:07:28 +0000 (12:07 +0000)
Incorrect read was happening after nodes which are not affect on output
were removed from the graph. Other nodes could have been connected to
this nodes which lead to accessing freed memory in some other places.

Solved by removing links from unused nodes before removing them from
the graph.

intern/cycles/render/graph.cpp

index 18e802b610de4be2701e2efe3db915cfeb332b45..ce715ad38939bac5b87682c0d1ac90254c156894 100644 (file)
@@ -402,6 +402,20 @@ void ShaderGraph::clean()
        /* break cycles */
        break_cycles(output(), visited, on_stack);
 
+       /* disconnect unused nodes */
+       foreach(ShaderNode *node, nodes) {
+               if(!visited[node->id]) {
+                       foreach(ShaderInput *to, node->inputs) {
+                               ShaderOutput *from = to->link;
+
+                               if (from) {
+                                       to->link = NULL;
+                                       from->links.erase(remove(from->links.begin(), from->links.end(), to), from->links.end());
+                               }
+                       }
+               }
+       }
+
        /* remove unused nodes */
        foreach(ShaderNode *node, nodes) {
                if(visited[node->id])