Commit: 33da997193b570f12db57fabcbe02e7283b7bbfc
Author: Campbell Barton
Date:   Thu Mar 26 12:49:10 2020 +1100
Branches: master
https://developer.blender.org/rB33da997193b570f12db57fabcbe02e7283b7bbfc

Fix crashes from various missing checks in operator poll functions

Issues exposed by 'bl_run_operators.py' utility.

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

M       source/blender/editors/animation/anim_markers.c
M       source/blender/editors/gpencil/gpencil_convert.c
M       source/blender/editors/gpencil/gpencil_edit.c
M       source/blender/editors/object/object_modifier.c
M       source/blender/editors/screen/screen_ops.c
M       source/blender/editors/sculpt_paint/paint_image_proj.c
M       source/blender/editors/sculpt_paint/paint_ops.c
M       source/blender/editors/transform/transform_ops.c

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

diff --git a/source/blender/editors/animation/anim_markers.c 
b/source/blender/editors/animation/anim_markers.c
index 7868d453268..8b0e9b22ce8 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -235,6 +235,9 @@ void ED_markers_get_minmax(ListBase *markers, short sel, 
float *r_first, float *
 static bool ED_operator_markers_region_active(bContext *C)
 {
   ScrArea *sa = CTX_wm_area(C);
+  if (sa == NULL) {
+    return false;
+  }
 
   switch (sa->spacetype) {
     case SPACE_ACTION: {
diff --git a/source/blender/editors/gpencil/gpencil_convert.c 
b/source/blender/editors/gpencil/gpencil_convert.c
index 1c55c3b5a8f..6e2c6936b1a 100644
--- a/source/blender/editors/gpencil/gpencil_convert.c
+++ b/source/blender/editors/gpencil/gpencil_convert.c
@@ -1755,7 +1755,7 @@ void GPENCIL_OT_convert(wmOperatorType *ot)
 static bool image_to_gpencil_poll(bContext *C)
 {
   SpaceLink *sl = CTX_wm_space_data(C);
-  if (sl->spacetype == SPACE_IMAGE) {
+  if ((sl != NULL) && (sl->spacetype == SPACE_IMAGE)) {
     return true;
   }
 
diff --git a/source/blender/editors/gpencil/gpencil_edit.c 
b/source/blender/editors/gpencil/gpencil_edit.c
index 83ecb3ab42f..1b42334499e 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -1379,7 +1379,8 @@ void GPENCIL_OT_copy(wmOperatorType *ot)
 
 static bool gp_strokes_paste_poll(bContext *C)
 {
-  if (CTX_wm_area(C)->spacetype != SPACE_VIEW3D) {
+  ScrArea *sa = CTX_wm_area(C);
+  if (!((sa != NULL) && (sa->spacetype == SPACE_VIEW3D))) {
     return false;
   }
   /* 1) Must have GP datablock to paste to
diff --git a/source/blender/editors/object/object_modifier.c 
b/source/blender/editors/object/object_modifier.c
index f6c13212976..0de2f114b94 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -1192,7 +1192,7 @@ static bool modifier_apply_poll(bContext *C)
   Object *ob = (ptr.owner_id != NULL) ? (Object *)ptr.owner_id : 
ED_object_active_context(C);
   ModifierData *md = ptr.data; /* May be NULL. */
 
-  if (ID_REAL_USERS(ob->data) > 1) {
+  if ((ob->data != NULL) && ID_REAL_USERS(ob->data) > 1) {
     CTX_wm_operator_poll_msg_set(C, "Modifiers cannot be applied to multi-user 
data");
     return false;
   }
diff --git a/source/blender/editors/screen/screen_ops.c 
b/source/blender/editors/screen/screen_ops.c
index 6a64e5212c4..d866b470d71 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -3142,7 +3142,7 @@ static void SCREEN_OT_screen_set(wmOperatorType *ot)
   ot->poll = ED_operator_screenactive;
 
   /* rna */
-  RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, 
INT_MAX);
+  RNA_def_int(ot->srna, "delta", 1, -1, 1, "Delta", "", -1, 1);
 }
 
 /** \} */
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 8362a4a576a..c56ce8fd183 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -64,6 +64,7 @@
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_customdata.h"
+#include "BKE_global.h"
 #include "BKE_idprop.h"
 #include "BKE_image.h"
 #include "BKE_lib_id.h"
@@ -6201,11 +6202,12 @@ void PAINT_OT_project_image(wmOperatorType *ot)
 
 static bool texture_paint_image_from_view_poll(bContext *C)
 {
-  if (BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0) == NULL) {
+  bScreen *screen = CTX_wm_screen(C);
+  if (!(screen && BKE_screen_find_big_area(screen, SPACE_VIEW3D, 0))) {
     CTX_wm_operator_poll_msg_set(C, "No 3D viewport found to create image 
from");
     return false;
   }
-  if (!GPU_is_initialized()) {
+  if (G.background || !GPU_is_initialized()) {
     return false;
   }
   return true;
@@ -6754,7 +6756,7 @@ void PAINT_OT_add_texture_paint_slot(wmOperatorType *ot)
   /* api callbacks */
   ot->invoke = texture_paint_add_texture_paint_slot_invoke;
   ot->exec = texture_paint_add_texture_paint_slot_exec;
-  ot->poll = ED_operator_object_active;
+  ot->poll = ED_operator_object_active_editable_mesh;
 
   /* flags */
   ot->flag = OPTYPE_UNDO;
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c 
b/source/blender/editors/sculpt_paint/paint_ops.c
index 0ed657ba460..ff0852aaf16 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -303,7 +303,7 @@ static void PALETTE_OT_color_delete(wmOperatorType *ot)
 static bool palette_extract_img_poll(bContext *C)
 {
   SpaceLink *sl = CTX_wm_space_data(C);
-  if (sl->spacetype == SPACE_IMAGE) {
+  if ((sl != NULL) && (sl->spacetype == SPACE_IMAGE)) {
     return true;
   }
 
diff --git a/source/blender/editors/transform/transform_ops.c 
b/source/blender/editors/transform/transform_ops.c
index aaf7fbc3108..7e56b34af2f 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -1031,7 +1031,7 @@ static void TRANSFORM_OT_bbone_resize(struct 
wmOperatorType *ot)
   ot->exec = transform_exec;
   ot->modal = transform_modal;
   ot->cancel = transform_cancel;
-  ot->poll = ED_operator_screenactive;
+  ot->poll = ED_operator_editarmature;
   ot->poll_property = transform_poll_property;
 
   RNA_def_float_translation(

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to