Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2021-10-19 17:17:04 +0300
committerSybren A. Stüvel <sybren@blender.org>2021-10-19 17:17:04 +0300
commit1c5722ba071ac08042f2e3150495b865a0ffa95a (patch)
tree0e42ee74d5a9dbc3343a1da895dd406f10e4812a /source/blender/editors/asset
parent0a6cf3ed0c64a0e4e58ecd40a491d0e6c93532f2 (diff)
Fix T91197: marking assets from Python may crash
When using `asset_mark` function from a Python script and afterwards updating the preview image, a crash might happen. The preview image is generated by the `asset_mark` function. This may happen on a background thread, introducing potential synchronization issues. This patch fixes this by separating the preview generation `ID.asset_generate_preview` from the mark as asset `ID.asset_mark`. Note: this separation of "mark as asset" and "generate preview" also applies to the `ED_asset_mark_id()` C function; if it is desired to have previews rendered after marking as asset, a call to `ED_asset_generate_preview()` is now also required. Reviewed By: sybren Maniphest Tasks: T91197 Differential Revision: https://developer.blender.org/D12922
Diffstat (limited to 'source/blender/editors/asset')
-rw-r--r--source/blender/editors/asset/ED_asset_mark_clear.h9
-rw-r--r--source/blender/editors/asset/intern/asset_mark_clear.cc9
-rw-r--r--source/blender/editors/asset/intern/asset_ops.cc4
3 files changed, 17 insertions, 5 deletions
diff --git a/source/blender/editors/asset/ED_asset_mark_clear.h b/source/blender/editors/asset/ED_asset_mark_clear.h
index d8b8f15a109..bab1d1bf8a5 100644
--- a/source/blender/editors/asset/ED_asset_mark_clear.h
+++ b/source/blender/editors/asset/ED_asset_mark_clear.h
@@ -34,7 +34,14 @@ struct bContext;
*
* \return whether the datablock was marked as asset; false when it is not capable of becoming an
* asset, or when it already was an asset. */
-bool ED_asset_mark_id(const struct bContext *C, struct ID *id);
+bool ED_asset_mark_id(struct ID *id);
+
+/**
+ * Generate preview image for the given datablock.
+ *
+ * The preview image might be generated using a background thread.
+ */
+void ED_asset_generate_preview(const struct bContext *C, struct ID *id);
/**
* Remove the asset metadata, turning the ID into a "normal" ID.
diff --git a/source/blender/editors/asset/intern/asset_mark_clear.cc b/source/blender/editors/asset/intern/asset_mark_clear.cc
index 8290124c209..e7516bc94c4 100644
--- a/source/blender/editors/asset/intern/asset_mark_clear.cc
+++ b/source/blender/editors/asset/intern/asset_mark_clear.cc
@@ -40,7 +40,7 @@
#include "ED_asset_list.h"
#include "ED_asset_mark_clear.h"
-bool ED_asset_mark_id(const bContext *C, ID *id)
+bool ED_asset_mark_id(ID *id)
{
if (id->asset_data) {
return false;
@@ -53,14 +53,17 @@ bool ED_asset_mark_id(const bContext *C, ID *id)
id->asset_data = BKE_asset_metadata_create();
- UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true);
-
/* Important for asset storage to update properly! */
ED_assetlist_storage_tag_main_data_dirty();
return true;
}
+void ED_asset_generate_preview(const bContext *C, ID *id)
+{
+ UI_icon_render_id(C, nullptr, id, ICON_SIZE_PREVIEW, true);
+}
+
bool ED_asset_clear_id(ID *id)
{
if (!id->asset_data) {
diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc
index bf532903c7c..33a22775280 100644
--- a/source/blender/editors/asset/intern/asset_ops.cc
+++ b/source/blender/editors/asset/intern/asset_ops.cc
@@ -145,7 +145,9 @@ void AssetMarkHelper::operator()(const bContext &C, PointerRNAVec &ids)
continue;
}
- if (ED_asset_mark_id(&C, id)) {
+ if (ED_asset_mark_id(id)) {
+ ED_asset_generate_preview(&C, id);
+
stats.last_id = id;
stats.tot_created++;
}