Fix: crash when accessing attributes from multiple threads
Calling two non-const methods on a `MutableAttributeAccessor` at the same time in multiple threads is not safe. While I don't know what caused the crash here exactly, I do know that it happens while looking up the attribute for writing, which may modify the unterlying geometry. I couldn't reproduce the bug with a debug build or without threading.
This commit is contained in:
@@ -1163,8 +1163,8 @@ static CurvesGeometry copy_with_removed_points(const CurvesGeometry &curves,
|
|||||||
threading::parallel_invoke(
|
threading::parallel_invoke(
|
||||||
/* Initialize curve offsets. */
|
/* Initialize curve offsets. */
|
||||||
[&]() { new_curves.offsets_for_write().copy_from(new_curve_offsets); },
|
[&]() { new_curves.offsets_for_write().copy_from(new_curve_offsets); },
|
||||||
/* Copy over point attributes. */
|
|
||||||
[&]() {
|
[&]() {
|
||||||
|
/* Copy over point attributes. */
|
||||||
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
||||||
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_POINT)) {
|
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_POINT)) {
|
||||||
threading::parallel_for(copy_point_ranges.index_range(), 128, [&](IndexRange range) {
|
threading::parallel_for(copy_point_ranges.index_range(), 128, [&](IndexRange range) {
|
||||||
@@ -1179,11 +1179,10 @@ static CurvesGeometry copy_with_removed_points(const CurvesGeometry &curves,
|
|||||||
});
|
});
|
||||||
attribute.dst.finish();
|
attribute.dst.finish();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
/* Copy over curve attributes.
|
/* Copy over curve attributes.
|
||||||
* In some cases points are just dissolved, so the the number of
|
* In some cases points are just dissolved, so the the number of
|
||||||
* curves will be the same. That could be optimized in the future. */
|
* curves will be the same. That could be optimized in the future. */
|
||||||
[&]() {
|
|
||||||
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
||||||
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_CURVE)) {
|
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_CURVE)) {
|
||||||
if (new_curves.curves_num() == curves.curves_num()) {
|
if (new_curves.curves_num() == curves.curves_num()) {
|
||||||
@@ -1260,8 +1259,8 @@ static CurvesGeometry copy_with_removed_curves(const CurvesGeometry &curves,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/* Copy over point attributes. */
|
|
||||||
[&]() {
|
[&]() {
|
||||||
|
/* Copy over point attributes. */
|
||||||
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
||||||
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_POINT)) {
|
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_POINT)) {
|
||||||
threading::parallel_for(old_curve_ranges.index_range(), 128, [&](IndexRange range) {
|
threading::parallel_for(old_curve_ranges.index_range(), 128, [&](IndexRange range) {
|
||||||
@@ -1275,9 +1274,7 @@ static CurvesGeometry copy_with_removed_curves(const CurvesGeometry &curves,
|
|||||||
});
|
});
|
||||||
attribute.dst.finish();
|
attribute.dst.finish();
|
||||||
}
|
}
|
||||||
},
|
/* Copy over curve attributes. */
|
||||||
/* Copy over curve attributes. */
|
|
||||||
[&]() {
|
|
||||||
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
for (auto &attribute : bke::retrieve_attributes_for_transfer(
|
||||||
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_CURVE)) {
|
curves.attributes(), new_curves.attributes_for_write(), ATTR_DOMAIN_MASK_CURVE)) {
|
||||||
threading::parallel_for(old_curve_ranges.index_range(), 128, [&](IndexRange range) {
|
threading::parallel_for(old_curve_ranges.index_range(), 128, [&](IndexRange range) {
|
||||||
|
|||||||
Reference in New Issue
Block a user