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.
This commit is contained in:
Jeroen Bakker 2018-06-19 16:33:47 +02:00
parent a7e66d89d0
commit 0116c95d4c
5 changed files with 18 additions and 25 deletions

View File

@ -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);

View File

@ -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();
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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);