Commit: fe4df40f3086d7fc135e17a15e0c4060f6b66dae
Author: Brecht Van Lommel
Date:   Tue Nov 13 15:16:03 2018 +0100
Branches: blender2.8
https://developer.blender.org/rBfe4df40f3086d7fc135e17a15e0c4060f6b66dae

Fix crash when Python creates modal keymaps without items.

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

M       source/blender/windowmanager/intern/wm_event_system.c
M       source/blender/windowmanager/intern/wm_keymap.c

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

diff --git a/source/blender/windowmanager/intern/wm_event_system.c 
b/source/blender/windowmanager/intern/wm_event_system.c
index 129d8ab1f8e..fcda06a7c2d 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -4589,7 +4589,7 @@ bool WM_window_modal_keymap_status_draw(
                        }
                }
        }
-       if (keymap == NULL) {
+       if (keymap == NULL || keymap->modal_items == NULL) {
                return false;
        }
        const EnumPropertyItem *items = keymap->modal_items;
diff --git a/source/blender/windowmanager/intern/wm_keymap.c 
b/source/blender/windowmanager/intern/wm_keymap.c
index 2bba4fc6f54..6078f0b92ce 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -802,21 +802,22 @@ wmKeyMap *WM_modalkeymap_add(wmKeyConfig *keyconf, const 
char *idname, const Enu
 {
        wmKeyMap *km = WM_keymap_ensure(keyconf, idname, 0, 0);
        km->flag |= KEYMAP_MODAL;
-       km->modal_items = items;
 
-       if (!items) {
-               /* init modal items from default config */
-               wmWindowManager *wm = G_MAIN->wm.first;
-               if (wm->defaultconf) {
-                       wmKeyMap *defaultkm = 
WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, 0, 0);
+       /* init modal items from default config */
+       wmWindowManager *wm = G_MAIN->wm.first;
+       if (wm->defaultconf && wm->defaultconf != keyconf) {
+               wmKeyMap *defaultkm = 
WM_keymap_list_find(&wm->defaultconf->keymaps, km->idname, 0, 0);
 
-                       if (defaultkm) {
-                               km->modal_items = defaultkm->modal_items;
-                               km->poll = defaultkm->poll;
-                       }
+               if (defaultkm) {
+                       km->modal_items = defaultkm->modal_items;
+                       km->poll = defaultkm->poll;
                }
        }
 
+       if (items) {
+               km->modal_items = items;
+       }
+
        return km;
 }
 
@@ -920,11 +921,13 @@ static void 
wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km)
                km->modal_items = defaultkm->modal_items;
                km->poll = defaultkm->poll;
 
-               for (kmi = km->items.first; kmi; kmi = kmi->next) {
-                       if (kmi->propvalue_str[0]) {
-                               if (RNA_enum_value_from_id(km->modal_items, 
kmi->propvalue_str, &propvalue))
-                                       kmi->propvalue = propvalue;
-                               kmi->propvalue_str[0] = '\0';
+               if (km->modal_items) {
+                       for (kmi = km->items.first; kmi; kmi = kmi->next) {
+                               if (kmi->propvalue_str[0]) {
+                                       if 
(RNA_enum_value_from_id(km->modal_items, kmi->propvalue_str, &propvalue))
+                                               kmi->propvalue = propvalue;
+                                       kmi->propvalue_str[0] = '\0';
+                               }
                        }
                }
        }

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

Reply via email to