[Bf-blender-cvs] [524d9a3e2fa] blender-v3.3-release: Fix error in operator poll functions

Campbell Barton noreply at git.blender.org
Tue Aug 30 13:07:03 CEST 2022


Commit: 524d9a3e2fa1821d0f846877ecb3936b7c3794dd
Author: Campbell Barton
Date:   Tue Aug 30 20:56:59 2022 +1000
Branches: blender-v3.3-release
https://developer.blender.org/rB524d9a3e2fa1821d0f846877ecb3936b7c3794dd

Fix error in operator poll functions

- PALETTE_OT_color_add: crashed without a brush.
- SCREEN_OT_actionzone: crashed without a window.
- PREFERENCES_OT_studiolight_show: exception when opening prefs failed.

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

M	release/scripts/startup/bl_operators/userpref.py
M	source/blender/editors/screen/screen_ops.c
M	source/blender/editors/sculpt_paint/paint_ops.c

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

diff --git a/release/scripts/startup/bl_operators/userpref.py b/release/scripts/startup/bl_operators/userpref.py
index 54de9c28144..ce23024fed5 100644
--- a/release/scripts/startup/bl_operators/userpref.py
+++ b/release/scripts/startup/bl_operators/userpref.py
@@ -1116,6 +1116,10 @@ class PREFERENCES_OT_studiolight_show(Operator):
     bl_label = ""
     bl_options = {'INTERNAL'}
 
+    @classmethod
+    def poll(cls, _context):
+        return bpy.ops.screen.userpref_show.poll()
+
     def execute(self, context):
         context.preferences.active_section = 'LIGHTS'
         bpy.ops.screen.userpref_show('INVOKE_DEFAULT')
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 3618b933443..c069b3c6292 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -723,15 +723,16 @@ typedef struct sActionzoneData {
 static bool actionzone_area_poll(bContext *C)
 {
   wmWindow *win = CTX_wm_window(C);
-  bScreen *screen = WM_window_get_active_screen(win);
-
-  if (screen && win && win->eventstate) {
-    const int *xy = &win->eventstate->xy[0];
+  if (win && win->eventstate) {
+    bScreen *screen = WM_window_get_active_screen(win);
+    if (screen) {
+      const int *xy = &win->eventstate->xy[0];
 
-    LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
-      LISTBASE_FOREACH (AZone *, az, &area->actionzones) {
-        if (BLI_rcti_isect_pt_v(&az->rect, xy)) {
-          return true;
+      LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+        LISTBASE_FOREACH (AZone *, az, &area->actionzones) {
+          if (BLI_rcti_isect_pt_v(&az->rect, xy)) {
+            return true;
+          }
         }
       }
     }
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 994ae4011b4..b78c60e7964 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -361,7 +361,6 @@ static int palette_color_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
   Scene *scene = CTX_data_scene(C);
   Paint *paint = BKE_paint_get_active_from_context(C);
-  Brush *brush = paint->brush;
   ePaintMode mode = BKE_paintmode_get_active_from_context(C);
   Palette *palette = paint->palette;
   PaletteColor *color;
@@ -369,17 +368,20 @@ static int palette_color_add_exec(bContext *C, wmOperator *UNUSED(op))
   color = BKE_palette_color_add(palette);
   palette->active_color = BLI_listbase_count(&palette->colors) - 1;
 
-  if (ELEM(mode,
-           PAINT_MODE_TEXTURE_3D,
-           PAINT_MODE_TEXTURE_2D,
-           PAINT_MODE_VERTEX,
-           PAINT_MODE_SCULPT)) {
-    copy_v3_v3(color->rgb, BKE_brush_color_get(scene, brush));
-    color->value = 0.0;
-  }
-  else if (mode == PAINT_MODE_WEIGHT) {
-    zero_v3(color->rgb);
-    color->value = brush->weight;
+  if (paint->brush) {
+    const Brush *brush = paint->brush;
+    if (ELEM(mode,
+             PAINT_MODE_TEXTURE_3D,
+             PAINT_MODE_TEXTURE_2D,
+             PAINT_MODE_VERTEX,
+             PAINT_MODE_SCULPT)) {
+      copy_v3_v3(color->rgb, BKE_brush_color_get(scene, brush));
+      color->value = 0.0;
+    }
+    else if (mode == PAINT_MODE_WEIGHT) {
+      zero_v3(color->rgb);
+      color->value = brush->weight;
+    }
   }
 
   return OPERATOR_FINISHED;



More information about the Bf-blender-cvs mailing list