[Bf-blender-cvs] [13beeb58922] master: Fix (unreported) load image code calling icin/preview update from non-Main thread.

Bastien Montagne noreply at git.blender.org
Fri May 11 10:49:36 CEST 2018


Commit: 13beeb58922747cc1a28bac58ceb1b44820808cd
Author: Bastien Montagne
Date:   Fri May 11 10:48:04 2018 +0200
Branches: master
https://developer.blender.org/rB13beeb58922747cc1a28bac58ceb1b44820808cd

Fix (unreported) load image code calling icin/preview update from non-Main thread.

Icin/preview only works in main thread, while image loading can be done
from others too... This could have generated random crashes and such.

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

M	source/blender/blenkernel/intern/icons.c
M	source/blender/blenkernel/intern/image.c

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

diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 3ac8abd55f6..9483543f1f0 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -514,8 +514,12 @@ static int icon_id_ensure_create_icon(struct ID *id)
 
 int BKE_icon_id_ensure(struct ID *id)
 {
-	if (!id || G.background)
+	/* Never handle icons in non-main thread! */
+	BLI_assert(BLI_thread_is_main());
+
+	if (!id || G.background) {
 		return 0;
+	}
 
 	if (id->icon_id)
 		return id->icon_id;
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index e8b5ce77613..8fd672963c7 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -3133,9 +3133,11 @@ static void image_create_multilayer(Image *ima, ImBuf *ibuf, int framenr)
 /* common stuff to do with images after loading */
 static void image_initialize_after_load(Image *ima, ImBuf *ibuf)
 {
-	/* preview is NULL when it has never been used as an icon before */
-	if (G.background == 0 && ima->preview == NULL)
+	/* Preview is NULL when it has never been used as an icon before.
+	 * Never handle previews/icons outside of main thread. */
+	if (G.background == 0 && ima->preview == NULL && BLI_thread_is_main()) {
 		BKE_icon_changed(BKE_icon_id_ensure(&ima->id));
+	}
 
 	/* fields */
 	if (ima->flag & IMA_FIELDS) {



More information about the Bf-blender-cvs mailing list