diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-02 05:44:37 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2020-09-02 16:00:05 +0300 |
commit | 006ff645388628eb82c47acc3a595a6d80cd7d8d (patch) | |
tree | 9c89991cb177fb7e3708d07ac8bc54d349a83da4 /source/blender | |
parent | c4b9e2da8c3c12e69b9a7eab8d9f8a12e65dccaa (diff) |
Fix crash accessing image space properties without an active window
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/include/ED_image.h | 2 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 3 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_edit.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_space.c | 29 |
6 files changed, 30 insertions, 21 deletions
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index 910cf362a37..81ef1593d58 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -106,7 +106,7 @@ bool ED_space_image_show_uvedit(struct SpaceImage *sima, struct Object *obedit); bool ED_space_image_paint_curve(const struct bContext *C); -bool ED_space_image_check_show_maskedit(struct SpaceImage *sima, struct ViewLayer *view_layer); +bool ED_space_image_check_show_maskedit(struct SpaceImage *sima, struct Object *obedit); bool ED_space_image_maskedit_poll(struct bContext *C); bool ED_space_image_maskedit_mask_poll(struct bContext *C); bool ED_space_image_cursor_poll(struct bContext *C); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 90813c9351c..37427eb8321 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -610,7 +610,8 @@ bool ED_operator_mask(bContext *C) case SPACE_IMAGE: { SpaceImage *sima = area->spacedata.first; ViewLayer *view_layer = CTX_data_view_layer(C); - return ED_space_image_check_show_maskedit(sima, view_layer); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + return ED_space_image_check_show_maskedit(sima, obedit); } } } diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index 6a37c094dac..39be2cbfa52 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -475,11 +475,10 @@ bool ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit) } /* matches clip function */ -bool ED_space_image_check_show_maskedit(SpaceImage *sima, ViewLayer *view_layer) +bool ED_space_image_check_show_maskedit(SpaceImage *sima, Object *obedit) { /* check editmode - this is reserved for UV editing */ - Object *ob = OBACT(view_layer); - if (ob && ob->mode & OB_MODE_EDIT && ED_space_image_show_uvedit(sima, ob)) { + if (obedit && ED_space_image_show_uvedit(sima, obedit)) { return false; } @@ -492,7 +491,8 @@ bool ED_space_image_maskedit_poll(bContext *C) if (sima) { ViewLayer *view_layer = CTX_data_view_layer(C); - return ED_space_image_check_show_maskedit(sima, view_layer); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + return ED_space_image_check_show_maskedit(sima, obedit); } return false; diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 7889e56ecfe..2e5b27bcf4a 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -905,7 +905,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } } - else if (ED_space_image_check_show_maskedit(sima, view_layer)) { + else if (ED_space_image_check_show_maskedit(sima, obedit)) { if (!ED_mask_selected_minmax(C, min, max)) { return OPERATOR_CANCELLED; } diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 1e1d4373fea..3b73e9f92f3 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -368,10 +368,9 @@ static void image_listener(wmWindow *win, ScrArea *area, wmNotifier *wmn, Scene } break; case NC_MASK: { - // Scene *scene = wmn->window->screen->scene; - /* ideally would check for: ED_space_image_check_show_maskedit(scene, sima) - * but we cant get the scene */ - if (sima->mode == SI_MODE_MASK) { + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + if (ED_space_image_check_show_maskedit(sima, obedit)) { switch (wmn->data) { case ND_SELECT: ED_area_tag_redraw(area); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index d4d35e07c2a..b02bf375349 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1455,11 +1455,14 @@ static bool rna_SpaceImageEditor_show_paint_get(PointerRNA *ptr) static bool rna_SpaceImageEditor_show_uvedit_get(PointerRNA *ptr) { - SpaceImage *sima = (SpaceImage *)(ptr->data); + SpaceImage *sima = ptr->data; bScreen *screen = (bScreen *)ptr->owner_id; + Object *obedit = NULL; wmWindow *win = ED_screen_window_find(screen, G_MAIN->wm.first); - ViewLayer *view_layer = WM_window_get_active_view_layer(win); - Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + if (win != NULL) { + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + } return ED_space_image_show_uvedit(sima, obedit); } @@ -1467,22 +1470,28 @@ static bool rna_SpaceImageEditor_show_maskedit_get(PointerRNA *ptr) { SpaceImage *sima = (SpaceImage *)(ptr->data); bScreen *screen = (bScreen *)ptr->owner_id; + Object *obedit = NULL; wmWindow *win = ED_screen_window_find(screen, G_MAIN->wm.first); - ViewLayer *view_layer = WM_window_get_active_view_layer(win); - return ED_space_image_check_show_maskedit(sima, view_layer); + if (win != NULL) { + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + } + return ED_space_image_check_show_maskedit(sima, obedit); } static void rna_SpaceImageEditor_image_set(PointerRNA *ptr, PointerRNA value, struct ReportList *UNUSED(reports)) { - SpaceImage *sima = (SpaceImage *)(ptr->data); + BLI_assert(BKE_id_is_in_global_main(value.data)); + SpaceImage *sima = ptr->data; bScreen *screen = (bScreen *)ptr->owner_id; + Object *obedit = NULL; wmWindow *win = ED_screen_window_find(screen, G_MAIN->wm.first); - ViewLayer *view_layer = WM_window_get_active_view_layer(win); - Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); - - BLI_assert(BKE_id_is_in_global_main(value.data)); + if (win != NULL) { + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + } ED_space_image_set(G_MAIN, sima, obedit, (Image *)value.data, false); } |