Fix T60112: Smooth crashes w/ multiple views
authorCampbell Barton <ideasman42@gmail.com>
Tue, 22 Jan 2019 05:51:31 +0000 (16:51 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 22 Jan 2019 05:52:17 +0000 (16:52 +1100)
source/blender/windowmanager/gizmo/WM_gizmo_api.h
source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c
source/blender/windowmanager/intern/wm_event_system.c

index 4ceb78b..667646c 100644 (file)
@@ -297,6 +297,9 @@ void WM_gizmomaptype_group_init_runtime_keymap(
 void WM_gizmomaptype_group_init_runtime(
         const struct Main *bmain, struct wmGizmoMapType *gzmap_type,
         struct wmGizmoGroupType *gzgt);
+void WM_gizmomaptype_group_init_runtime_with_region(
+        struct wmGizmoMapType *gzmap_type,
+        struct wmGizmoGroupType *gzgt, struct ARegion *ar);
 void WM_gizmomaptype_group_unlink(
         struct bContext *C, struct Main *bmain, struct wmGizmoMapType *gzmap_type,
         const struct wmGizmoGroupType *gzgt);
index 67b7149..9999f40 100644 (file)
@@ -792,6 +792,11 @@ void WM_gizmomaptype_group_init_runtime(
         const Main *bmain, wmGizmoMapType *gzmap_type,
         wmGizmoGroupType *gzgt)
 {
+       /* Tools add themselves. */
+       if (gzgt->flag & WM_GIZMOGROUPTYPE_TOOL_INIT) {
+               return;
+       }
+
        /* now create a gizmo for all existing areas */
        for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
                for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
@@ -800,11 +805,7 @@ void WM_gizmomaptype_group_init_runtime(
                                for (ARegion *ar = lb->first; ar; ar = ar->next) {
                                        wmGizmoMap *gzmap = ar->gizmo_map;
                                        if (gzmap && gzmap->type == gzmap_type) {
-                                               wm_gizmogroup_new_from_type(gzmap, gzgt);
-
-                                               /* just add here, drawing will occur on next update */
-                                               wm_gizmomap_highlight_set(gzmap, NULL, NULL, 0);
-                                               ED_region_tag_redraw(ar);
+                                               WM_gizmomaptype_group_init_runtime_with_region(gzmap_type, gzgt, ar);
                                        }
                                }
                        }
@@ -812,6 +813,18 @@ void WM_gizmomaptype_group_init_runtime(
        }
 }
 
+void WM_gizmomaptype_group_init_runtime_with_region(
+        wmGizmoMapType *gzmap_type,
+        wmGizmoGroupType *gzgt, ARegion *ar)
+{
+       wmGizmoMap *gzmap = ar->gizmo_map;
+       BLI_assert(gzmap && gzmap->type == gzmap_type);
+
+       wm_gizmogroup_new_from_type(gzmap, gzgt);
+
+       wm_gizmomap_highlight_set(gzmap, NULL, NULL, 0);
+       ED_region_tag_redraw(ar);
+}
 
 /**
  * Unlike #WM_gizmomaptype_group_unlink this doesn't maintain correct state, simply free.
index a2850a7..5feacea 100644 (file)
@@ -2057,7 +2057,12 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
                                                wmGizmoGroupType *gzgt = WM_gizmogrouptype_find(idname, false);
                                                if (gzgt != NULL) {
                                                        if ((gzgt->flag & WM_GIZMOGROUPTYPE_TOOL_INIT) != 0) {
-                                                               WM_gizmo_group_type_ensure_ptr(gzgt);
+                                                               ARegion *ar = CTX_wm_region(C);
+                                                               if (ar != NULL) {
+                                                                       wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure(&gzgt->gzmap_params);
+                                                                       WM_gizmo_group_type_ensure_ptr_ex(gzgt, gzmap_type);
+                                                                       WM_gizmomaptype_group_init_runtime_with_region(gzmap_type, gzgt, ar);
+                                                               }
                                                        }
                                                }
                                        }