[Bf-blender-cvs] [81ac0bf759d] master: Fix failing "Edit Source" (asserts) while number slider was visible

Julian Eisel noreply at git.blender.org
Thu Feb 18 17:17:59 CET 2021


Commit: 81ac0bf759d34e7de921784250d82540cb218718
Author: Julian Eisel
Date:   Thu Feb 18 16:33:00 2021 +0100
Branches: master
https://developer.blender.org/rB81ac0bf759d34e7de921784250d82540cb218718

Fix failing "Edit Source" (asserts) while number slider was visible

E.g. steps to reproduce:
* Enter Vertex Paint mode
* In the tool settings, right-click > "Edit Source"

When creating a number slider via `layout.prop(..., slider=True)`, the UI code
would reallocate the number button to be a number-slider button. That's because
we now actually have different button data-structures for these (see
e6f0b60c2e911). The edit source code stored data based on the button pointers,
which didn't get updated after changing the type. The fix just adds this
updating.

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_ops.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 75100326fac..bc013953b1e 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2545,6 +2545,7 @@ void UI_template_fix_linking(void);
 /* UI_OT_editsource helpers */
 bool UI_editsource_enable_check(void);
 void UI_editsource_active_but_test(uiBut *but);
+void UI_editsource_but_replace(const uiBut *old_but, uiBut *new_but);
 
 /* UI_butstore_ helpers */
 typedef struct uiButStore uiButStore;
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 10cbc2dc5fa..711d67710ad 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3948,6 +3948,9 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type)
       UNUSED_VARS_NDEBUG(found_layout);
       ui_button_group_replace_but_ptr(uiLayoutGetBlock(but->layout), old_but_ptr, but);
     }
+    if (UI_editsource_enable_check()) {
+      UI_editsource_but_replace(old_but_ptr, but);
+    }
   }
 
   return but;
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 05a2a6ef29b..540e98f542e 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -1296,6 +1296,19 @@ void UI_editsource_active_but_test(uiBut *but)
   BLI_ghash_insert(ui_editsource_info->hash, but, but_store);
 }
 
+/**
+ * Remove the editsource data for \a old_but and reinsert it for \a new_but. Use when the button
+ * was reallocated, e.g. to have a new type (#ui_but_change_type()).
+ */
+void UI_editsource_but_replace(const uiBut *old_but, uiBut *new_but)
+{
+  uiEditSourceButStore *but_store = BLI_ghash_lookup(ui_editsource_info->hash, old_but);
+  if (but_store) {
+    BLI_ghash_remove(ui_editsource_info->hash, old_but, NULL, NULL);
+    BLI_ghash_insert(ui_editsource_info->hash, new_but, but_store);
+  }
+}
+
 static int editsource_text_edit(bContext *C,
                                 wmOperator *op,
                                 const char filepath[FILE_MAX],



More information about the Bf-blender-cvs mailing list