[Bf-blender-cvs] [0116c95d4c9] blender2.8: Studiolight: Temp Mutex issue

Jeroen Bakker noreply at git.blender.org
Tue Jun 19 16:38:38 CEST 2018


Commit: 0116c95d4c9114bc9eae03401c0471fba265cd46
Author: Jeroen Bakker
Date:   Tue Jun 19 16:33:47 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0116c95d4c9114bc9eae03401c0471fba265cd46

Studiolight: Temp Mutex issue

This is a temp fix for a better system.
Currently the studiolights can be referenced by a WM_job and being freed
via the API. This can happen when removing a studiolight via the
interface.

As the studiolight has no relation with the job, it is hard to detect if
it is still being used. I tried with a Mutex and a Thread Queue but they
were failing.

So the current temp fix is to keep the studiolights in memory until you
close blender. This Must be fixed ASAP! I added this fix so normal cases
can workish.

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

M	source/blender/blenkernel/BKE_studiolight.h
M	source/blender/blenkernel/intern/studiolight.c
M	source/blender/editors/interface/interface_icons.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/source/blender/blenkernel/BKE_studiolight.h b/source/blender/blenkernel/BKE_studiolight.h
index 7ffb75820df..a1f43352d8b 100644
--- a/source/blender/blenkernel/BKE_studiolight.h
+++ b/source/blender/blenkernel/BKE_studiolight.h
@@ -79,6 +79,7 @@ enum StudioLightFlag {
 	STUDIOLIGHT_EQUIRECTANGULAR_IRRADIANCE_GPUTEXTURE       = (1 << 10),
 	STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED                 = (1 << 11),
 	STUDIOLIGHT_UI_EXPANDED                                 = (1 << 13),
+	STUDIOLIGHT_DISABLED                                    = (1 << 14),
 } StudioLightFlag;
 
 #define STUDIOLIGHT_FLAG_ALL (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_EXTERNAL_FILE)
@@ -107,6 +108,7 @@ typedef struct StudioLight {
 	struct GPUTexture *equirectangular_radiance_gputexture;
 	struct GPUTexture *equirectangular_irradiance_gputexture;
 	float *gpu_matcap_3components; /* 3 channel buffer for GPU_R11F_G11F_B10F */
+
 } StudioLight;
 
 void BKE_studiolight_init(void);
diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c
index 3cdb8da75b5..42a6b96653f 100644
--- a/source/blender/blenkernel/intern/studiolight.c
+++ b/source/blender/blenkernel/intern/studiolight.c
@@ -115,6 +115,7 @@ static struct StudioLight *studiolight_create(int flag)
 	for (int index = 0 ; index < 6 ; index ++) {
 		sl->radiance_cubemap_buffers[index] = NULL;
 	}
+
 	return sl;
 }
 
@@ -891,7 +892,7 @@ void BKE_studiolight_free(void)
 struct StudioLight *BKE_studiolight_find_first(int flag)
 {
 	LISTBASE_FOREACH(StudioLight *, sl, &studiolights) {
-		if ((sl->flag & flag)) {
+		if ((sl->flag & flag) && (sl->flag & STUDIOLIGHT_DISABLED) == 0) {
 			return sl;
 		}
 	}
@@ -902,7 +903,7 @@ struct StudioLight *BKE_studiolight_find(const char *name, int flag)
 {
 	LISTBASE_FOREACH(StudioLight *, sl, &studiolights) {
 		if (STREQLEN(sl->name, name, FILE_MAXFILE)) {
-			if ((sl->flag & flag)) {
+			if ((sl->flag & flag) && (sl->flag & STUDIOLIGHT_DISABLED) == 0) {
 				return sl;
 			}
 			else {
@@ -918,7 +919,7 @@ struct StudioLight *BKE_studiolight_find(const char *name, int flag)
 struct StudioLight *BKE_studiolight_findindex(int index, int flag)
 {
 	LISTBASE_FOREACH(StudioLight *, sl, &studiolights) {
-		if (sl->index == index) {
+		if (sl->index == index  && (sl->flag & STUDIOLIGHT_DISABLED) == 0) {
 			return sl;
 		}
 	}
@@ -994,6 +995,8 @@ void BKE_studiolight_ensure_flag(StudioLight *sl, int flag)
 
 void BKE_studiolight_refresh(void)
 {
-	BKE_studiolight_free();
+	LISTBASE_FOREACH(StudioLight *, sl, &studiolights) {
+		sl->flag |= STUDIOLIGHT_DISABLED;
+	}
 	BKE_studiolight_init();
 }
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index 3d0e74a4023..3272e9f14a2 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -882,6 +882,7 @@ void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool bi
 					if (icon->obj_type == ICON_DATA_STUDIOLIGHT) {
 						if (di->data.buffer.image == NULL) {
 							IconImage *img = MEM_mallocN(sizeof(IconImage), __func__);
+
 							img->w = STUDIOLIGHT_ICON_SIZE;
 							img->h = STUDIOLIGHT_ICON_SIZE;
 							size_t size = STUDIOLIGHT_ICON_SIZE * STUDIOLIGHT_ICON_SIZE * sizeof(uint);
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 13ea2dd436e..c886f19d134 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -766,6 +766,9 @@ static const EnumPropertyItem *rna_View3DShading_studio_light_itemf(
 		const int flags = (STUDIOLIGHT_EXTERNAL_FILE | STUDIOLIGHT_ORIENTATION_VIEWNORMAL);
 
 		LISTBASE_FOREACH(StudioLight *, sl, BKE_studiolight_listbase()) {
+			if ((sl->flag & STUDIOLIGHT_DISABLED)){
+				continue;
+			}
 			int icon_id = (v3d->shading.flag & V3D_SHADING_MATCAP_FLIP_X) ? sl->icon_id_matcap_flipped: sl->icon_id_matcap;
 			if ((sl->flag & flags) == flags) {
 				EnumPropertyItem tmp = {sl->index, sl->name, icon_id, sl->name, ""};
@@ -775,10 +778,13 @@ static const EnumPropertyItem *rna_View3DShading_studio_light_itemf(
 	}
 	else {
 		LISTBASE_FOREACH(StudioLight *, sl, BKE_studiolight_listbase()) {
+			if ((sl->flag & STUDIOLIGHT_DISABLED)){
+				continue;
+			}
 			int icon_id = sl->icon_id_irradiance;
 			bool show_studiolight = false;
 
-			if ((sl->flag & STUDIOLIGHT_INTERNAL)) {
+			if (sl->flag & STUDIOLIGHT_INTERNAL) {
 				/* always show internal lights */
 				show_studiolight = true;
 			}
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 215db672e02..6e0f95a33b7 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -703,24 +703,9 @@ static int rna_UserDef_studiolight_index_get(PointerRNA *ptr)
 static int rna_UserDef_studiolight_is_user_defined_get(PointerRNA *ptr)
 {
 	StudioLight *sl = (StudioLight *)ptr->data;
-	return (sl->flag & STUDIOLIGHT_USER_DEFINED) > 0;
+	return (sl->flag & STUDIOLIGHT_USER_DEFINED) > 0 && (sl->flag & STUDIOLIGHT_DISABLED) == 0;
 }
 
-/* StudioLight.show_expanded */
-static int rna_UserDef_studiolight_show_expanded_get(PointerRNA *ptr)
-{
-	StudioLight *sl = (StudioLight *)ptr->data;
-	return (sl->flag & STUDIOLIGHT_UI_EXPANDED) > 0;
-}
-
-static void rna_UserDef_studiolight_show_expanded_set(PointerRNA *ptr, const bool value)
-{
-	StudioLight *sl = (StudioLight *)ptr->data;
-	sl->flag ^= STUDIOLIGHT_UI_EXPANDED;
-	sl->flag |= value ? STUDIOLIGHT_UI_EXPANDED : 0;
-}
-
-
 /* StudioLight.orientation */
 
 static int rna_UserDef_studiolight_orientation_get(PointerRNA *ptr)
@@ -3269,10 +3254,6 @@ static void rna_def_userdef_studiolight(BlenderRNA *brna)
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "User Defined", "");
 
-	prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_funcs(prop, "rna_UserDef_studiolight_show_expanded_get", "rna_UserDef_studiolight_show_expanded_set");
-	RNA_def_property_ui_text(prop, "Show Expanded", "");
-
 	prop = RNA_def_property(srna, "orientation", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_items(prop, rna_enum_studio_light_orientation_items);
 	RNA_def_property_enum_funcs(prop, "rna_UserDef_studiolight_orientation_get", "rna_UserDef_studiolight_orientation_set", NULL);



More information about the Bf-blender-cvs mailing list