[Bf-blender-cvs] [90dae362133] master: Fix T66524: Eyedropper in popover crashes

Campbell Barton noreply at git.blender.org
Mon Jul 8 12:42:04 CEST 2019


Commit: 90dae36213316b338cbe6b31c41c746ee7a69b8e
Author: Campbell Barton
Date:   Mon Jul 8 20:39:27 2019 +1000
Branches: master
https://developer.blender.org/rB90dae36213316b338cbe6b31c41c746ee7a69b8e

Fix T66524: Eyedropper in popover crashes

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

M	source/blender/editors/interface/interface_eyedropper_colorband.c

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

diff --git a/source/blender/editors/interface/interface_eyedropper_colorband.c b/source/blender/editors/interface/interface_eyedropper_colorband.c
index 67e5a6c806c..ffe93e48936 100644
--- a/source/blender/editors/interface/interface_eyedropper_colorband.c
+++ b/source/blender/editors/interface/interface_eyedropper_colorband.c
@@ -84,22 +84,40 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op)
 
   uiBut *but = UI_context_active_but_get(C);
 
+  PointerRNA rna_update_ptr = PointerRNA_NULL;
+  PropertyRNA *rna_update_prop = NULL;
+  bool is_undo = true;
+
   if (but == NULL) {
     /* pass */
   }
-  else if (but->type == UI_BTYPE_COLORBAND) {
-    /* When invoked with a hotkey, we can find the band in 'but->poin'. */
-    band = (ColorBand *)but->poin;
-  }
   else {
-    /* When invoked from a button it's in custom_data field. */
-    band = (ColorBand *)but->custom_data;
+    if (but->type == UI_BTYPE_COLORBAND) {
+      /* When invoked with a hotkey, we can find the band in 'but->poin'. */
+      band = (ColorBand *)but->poin;
+    }
+    else {
+      /* When invoked from a button it's in custom_data field. */
+      band = (ColorBand *)but->custom_data;
+    }
+
+    if (band) {
+      rna_update_ptr = ((Colorband_RNAUpdateCb *)but->func_argN)->ptr;
+      rna_update_prop = ((Colorband_RNAUpdateCb *)but->func_argN)->prop;
+      is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
+    }
   }
 
   if (!band) {
     PointerRNA ptr = CTX_data_pointer_get_type(C, "color_ramp", &RNA_ColorRamp);
     if (ptr.data != NULL) {
       band = ptr.data;
+
+      /* Set this to a sub-member of the property to trigger an update. */
+      extern PropertyRNA rna_ColorRamp_color_mode;
+      rna_update_ptr = ptr;
+      rna_update_prop = &rna_ColorRamp_color_mode;
+      is_undo = RNA_struct_undo_check(ptr.type);
     }
   }
 
@@ -113,9 +131,9 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op)
   eye->color_buffer_len = 0;
   eye->color_band = band;
   eye->init_color_band = *eye->color_band;
-  eye->ptr = ((Colorband_RNAUpdateCb *)but->func_argN)->ptr;
-  eye->prop = ((Colorband_RNAUpdateCb *)but->func_argN)->prop;
-  eye->is_undo = UI_but_flag_is_set(but, UI_BUT_UNDO);
+  eye->ptr = rna_update_ptr;
+  eye->prop = rna_update_prop;
+  eye->is_undo = is_undo;
 
   op->customdata = eye;
 
@@ -186,7 +204,9 @@ static void eyedropper_colorband_apply(bContext *C, wmOperator *op)
   BKE_colorband_init_from_table_rgba(
       eye->color_band, eye->color_buffer, eye->color_buffer_len, filter_samples);
   eye->is_set = true;
-  RNA_property_update(C, &eye->ptr, eye->prop);
+  if (eye->prop) {
+    RNA_property_update(C, &eye->ptr, eye->prop);
+  }
 }
 
 static void eyedropper_colorband_cancel(bContext *C, wmOperator *op)
@@ -194,7 +214,9 @@ static void eyedropper_colorband_cancel(bContext *C, wmOperator *op)
   EyedropperColorband *eye = op->customdata;
   if (eye->is_set) {
     *eye->color_band = eye->init_color_band;
-    RNA_property_update(C, &eye->ptr, eye->prop);
+    if (eye->prop) {
+      RNA_property_update(C, &eye->ptr, eye->prop);
+    }
   }
   eyedropper_colorband_exit(C, op);
 }
@@ -267,7 +289,9 @@ static int eyedropper_colorband_point_modal(bContext *C, wmOperator *op, const w
         break;
       case EYE_MODAL_SAMPLE_RESET:
         *eye->color_band = eye->init_color_band;
-        RNA_property_update(C, &eye->ptr, eye->prop);
+        if (eye->prop) {
+          RNA_property_update(C, &eye->ptr, eye->prop);
+        }
         eye->color_buffer_len = 0;
         break;
     }



More information about the Bf-blender-cvs mailing list