[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40261] branches/cycles/intern/cycles/ render: Cycles: fix issue with mix shaders, leading to use of uninitialized memory.

Brecht Van Lommel brechtvanlommel at pandora.be
Fri Sep 16 15:00:09 CEST 2011


Revision: 40261
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40261
Author:   blendix
Date:     2011-09-16 13:00:09 +0000 (Fri, 16 Sep 2011)
Log Message:
-----------
Cycles: fix issue with mix shaders, leading to use of uninitialized memory.

Modified Paths:
--------------
    branches/cycles/intern/cycles/render/svm.cpp
    branches/cycles/intern/cycles/render/svm.h

Modified: branches/cycles/intern/cycles/render/svm.cpp
===================================================================
--- branches/cycles/intern/cycles/render/svm.cpp	2011-09-16 12:59:22 UTC (rev 40260)
+++ branches/cycles/intern/cycles/render/svm.cpp	2011-09-16 13:00:09 UTC (rev 40261)
@@ -230,6 +230,11 @@
 
 				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 @@
 
 			for(int i = 0; i < size; i++)
 				active_stack.users[input->stack_offset + i]--;
+
+			input->stack_offset = SVM_STACK_INVALID;
 		}
 	}
 }
@@ -397,6 +404,10 @@
 		/* 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 */

Modified: branches/cycles/intern/cycles/render/svm.h
===================================================================
--- branches/cycles/intern/cycles/render/svm.h	2011-09-16 12:59:22 UTC (rev 40260)
+++ branches/cycles/intern/cycles/render/svm.h	2011-09-16 13:00:09 UTC (rev 40261)
@@ -78,7 +78,28 @@
 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];
 	};
 




More information about the Bf-blender-cvs mailing list