diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-09-16 17:00:09 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-09-16 17:00:09 +0400 |
commit | 0a5fcf3da3e82fd114095c8c2903d927f15ffc31 (patch) | |
tree | ab7206829b29a4225c5b66e7456a9d1484a17834 /intern/cycles | |
parent | 376aede7a6dbe0d5beee4dc5fd89bd8608c36b09 (diff) |
Cycles: fix issue with mix shaders, leading to use of uninitialized memory.
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/render/svm.cpp | 11 | ||||
-rw-r--r-- | intern/cycles/render/svm.h | 21 |
2 files changed, 32 insertions, 0 deletions
diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp index c4188fda421..8f3682cc349 100644 --- a/intern/cycles/render/svm.cpp +++ b/intern/cycles/render/svm.cpp @@ -230,6 +230,11 @@ void SVMCompiler::stack_clear_users(ShaderNode *node, set<ShaderNode*>& done) for(int i = 0; i < size; i++) active_stack.users[output->stack_offset + i]--; + + output->stack_offset = SVM_STACK_INVALID; + + foreach(ShaderInput *in, output->links) + in->stack_offset = SVM_STACK_INVALID; } } } @@ -243,6 +248,8 @@ void SVMCompiler::stack_clear_temporary(ShaderNode *node) for(int i = 0; i < size; i++) active_stack.users[input->stack_offset + i]--; + + input->stack_offset = SVM_STACK_INVALID; } } } @@ -397,6 +404,10 @@ void SVMCompiler::generate_closure(ShaderNode *node, set<ShaderNode*> done, Stac /* set jump for mix node, -1 because offset is already incremented when this jump is added to it */ svm_nodes[mix_offset].z = cl2_offset - mix_offset - 1; + + done.insert(node); + stack_clear_users(node, done); + stack_clear_temporary(node); } else { /* execute dependencies for closure */ diff --git a/intern/cycles/render/svm.h b/intern/cycles/render/svm.h index 05fb85b057f..dfd78cf3c40 100644 --- a/intern/cycles/render/svm.h +++ b/intern/cycles/render/svm.h @@ -78,6 +78,27 @@ public: protected: struct Stack { Stack() { memset(users, 0, sizeof(users)); } + Stack(const Stack& other) { memcpy(users, other.users, sizeof(users)); } + Stack& operator=(const Stack& other) { memcpy(users, other.users, sizeof(users)); return *this; } + + bool empty() + { + for(int i = 0; i < SVM_STACK_SIZE; i++) + if(users[i]) + return false; + + return true; + } + + void print() + { + printf("stack <"); + + for(int i = 0; i < SVM_STACK_SIZE; i++) + printf((users[i])? "*": " "); + + printf(">\n"); + } int users[SVM_STACK_SIZE]; }; |