[Bf-blender-cvs] [265e5de] master: Fix T50104, Race condition in SVMShaderManager::device_update_shader

lazydodo noreply at git.blender.org
Fri Nov 25 20:03:16 CET 2016


Commit: 265e5def76cc08f633e8851236af1ee903d87ff0
Author: lazydodo
Date:   Fri Nov 25 12:02:37 2016 -0700
Branches: master
https://developer.blender.org/rB265e5def76cc08f633e8851236af1ee903d87ff0

Fix T50104, Race condition in SVMShaderManager::device_update_shader

===================================================================

M	intern/cycles/render/svm.cpp

===================================================================

diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp
index 9d3f49a..955b892 100644
--- a/intern/cycles/render/svm.cpp
+++ b/intern/cycles/render/svm.cpp
@@ -71,14 +71,13 @@ void SVMShaderManager::device_update_shader(Scene *scene,
 		scene->light_manager->need_update = true;
 	}
 
-	/* We only calculate offset and do re-allocation from the locked block,
-	 * actual copy we do after the lock is releases to hopefully gain some
-	 * percent of performance.
+	/* The copy needs to be done inside the lock, if another thread resizes the array 
+	 * while memcpy is running, it'll be copying into possibly invalid/freed ram. 
 	 */
 	nodes_lock_.lock();
 	size_t global_nodes_size = global_svm_nodes->size();
 	global_svm_nodes->resize(global_nodes_size + svm_nodes.size());
-	nodes_lock_.unlock();
+	
 	/* Offset local SVM nodes to a global address space. */
 	int4& jump_node = global_svm_nodes->at(shader->id);
 	jump_node.y = svm_nodes[0].y + global_nodes_size - 1;
@@ -88,6 +87,7 @@ void SVMShaderManager::device_update_shader(Scene *scene,
 	memcpy(&global_svm_nodes->at(global_nodes_size),
 	       &svm_nodes[1],
 	       sizeof(int4) * (svm_nodes.size() - 1));
+	nodes_lock_.unlock();
 }
 
 void SVMShaderManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)




More information about the Bf-blender-cvs mailing list