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:
authorBastien Montagne <montagne29@wanadoo.fr>2016-07-12 18:49:30 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2016-07-12 22:11:38 +0300
commit51812fb502c0a3034055df2c7b80e77dba5e91c3 (patch)
tree338ef5e0a1c4fa795f26362dd32fe80b2065bbbd /source/blender/blenkernel/intern/icons.c
parent5fae2503bf7d81b89f68f4c494f4c0e4c9eb5f46 (diff)
Fix 48831, Step I: Mismatch issues bewteen ID icon and preview system.
- icon_id from ID and PreviewImage were not guaranteed to be in sync. - PreviewImage one was not reset on file read. - Through RNA e.g., it was possible to ensure an ID icon via its preview image, which was running code designed for custom previews/icons system, instead of generating correct 'auto ID icon'.
Diffstat (limited to 'source/blender/blenkernel/intern/icons.c')
-rw-r--r--source/blender/blenkernel/intern/icons.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index f3e86b44459..63055dc0646 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -423,10 +423,26 @@ void BKE_icon_changed(int id)
}
}
-int BKE_icon_id_ensure(struct ID *id)
+static int icon_id_ensure_create_icon(struct ID *id)
{
Icon *new_icon = NULL;
+ new_icon = MEM_mallocN(sizeof(Icon), __func__);
+
+ new_icon->obj = id;
+ new_icon->type = GS(id->name);
+
+ /* next two lines make sure image gets created */
+ new_icon->drawinfo = NULL;
+ new_icon->drawinfo_free = NULL;
+
+ BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(id->icon_id), new_icon);
+
+ return id->icon_id;
+}
+
+int BKE_icon_id_ensure(struct ID *id)
+{
if (!id || G.background)
return 0;
@@ -440,32 +456,39 @@ int BKE_icon_id_ensure(struct ID *id)
return 0;
}
- new_icon = MEM_mallocN(sizeof(Icon), __func__);
-
- new_icon->obj = id;
- new_icon->type = GS(id->name);
-
- /* next two lines make sure image gets created */
- new_icon->drawinfo = NULL;
- new_icon->drawinfo_free = NULL;
+ /* Ensure we synchronize ID icon_id with its previewimage if it has one. */
+ PreviewImage **p_prv = BKE_previewimg_id_get_p(id);
+ if (p_prv && *p_prv) {
+ BLI_assert(ELEM((*p_prv)->icon_id, 0, id->icon_id));
+ (*p_prv)->icon_id = id->icon_id;
+ }
- BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(id->icon_id), new_icon);
-
- return id->icon_id;
+ return icon_id_ensure_create_icon(id);
}
/**
* Return icon id of given preview, or create new icon if not found.
*/
-int BKE_icon_preview_ensure(PreviewImage *preview)
+int BKE_icon_preview_ensure(ID *id, PreviewImage *preview)
{
Icon *new_icon = NULL;
if (!preview || G.background)
return 0;
- if (preview->icon_id)
+ if (id) {
+ BLI_assert(BKE_previewimg_id_ensure(id) == preview);
+ }
+
+ if (preview->icon_id) {
+ BLI_assert(!id || !id->icon_id || id->icon_id == preview->icon_id);
return preview->icon_id;
+ }
+
+ if (id && id->icon_id) {
+ preview->icon_id = id->icon_id;
+ return preview->icon_id;
+ }
preview->icon_id = get_next_free_id();
@@ -474,6 +497,12 @@ int BKE_icon_preview_ensure(PreviewImage *preview)
return 0;
}
+ /* Ensure we synchronize ID icon_id with its previewimage if available, and generate suitable 'ID' icon. */
+ if (id) {
+ id->icon_id = preview->icon_id;
+ return icon_id_ensure_create_icon(id);
+ }
+
new_icon = MEM_mallocN(sizeof(Icon), __func__);
new_icon->obj = preview;