[Bf-blender-cvs] [cbdedc1] master: Fix T38284: Crash with several shrinkwrap constraint using same target

Sergey Sharybin noreply at git.blender.org
Thu Jan 23 11:31:10 CET 2014


Commit: cbdedc169dd948d308dcdb1fc2e74b1fdd25880c
Author: Sergey Sharybin
Date:   Thu Jan 23 16:24:41 2014 +0600
https://developer.blender.org/rBcbdedc169dd948d308dcdb1fc2e74b1fdd25880c

Fix T38284: Crash with several shrinkwrap constraint using same target

Issue is caused by the race condition between getting custom data layers
from target's derived mesh (for vertices and faces) and releasing this
derived mesh from other threads.

When one releases the derived mesh it'll free temporary data from it,
and it'll also update data layers mapping.

General rule for threading is that no one is ever allowed to modify
data he doesn't own. This means that no temp layers are to be allocated
in derived mesh and making it so `CustomData_free_temporary()` doesn't
update mapping if nothing was freed will solve the race condition.

It is still possible to do other improvements, namely detect which
additional data/layers are to be present in derived mesh and create
it as a part of `object_handle_update()`, but this is to be solved
separately.

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

M	source/blender/blenkernel/intern/customdata.c

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

diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index ccb167a..fc123d3 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1914,6 +1914,7 @@ void CustomData_free_temporary(CustomData *data, int totelem)
 {
 	CustomDataLayer *layer;
 	int i, j;
+	bool changed = false;
 
 	for (i = 0, j = 0; i < data->totlayer; ++i) {
 		layer = &data->layers[i];
@@ -1921,18 +1922,24 @@ void CustomData_free_temporary(CustomData *data, int totelem)
 		if (i != j)
 			data->layers[j] = data->layers[i];
 
-		if ((layer->flag & CD_FLAG_TEMPORARY) == CD_FLAG_TEMPORARY)
+		if ((layer->flag & CD_FLAG_TEMPORARY) == CD_FLAG_TEMPORARY) {
 			customData_free_layer__internal(layer, totelem);
+			changed = true;
+		}
 		else
 			j++;
 	}
 
 	data->totlayer = j;
 
-	if (data->totlayer <= data->maxlayer - CUSTOMDATA_GROW)
+	if (data->totlayer <= data->maxlayer - CUSTOMDATA_GROW) {
 		customData_resize(data, -CUSTOMDATA_GROW);
+		changed = true;
+	}
 
-	customData_update_offsets(data);
+	if (changed) {
+		customData_update_offsets(data);
+	}
 }
 
 void CustomData_set_only_copy(const struct CustomData *data,




More information about the Bf-blender-cvs mailing list