[Bf-blender-cvs] [578dff78636] master: Fix assertion when notifiers weren't removed from the notifier queue set

Campbell Barton noreply at git.blender.org
Sat Aug 27 04:30:15 CEST 2022


Commit: 578dff786362ba0d1426d1d3d15d579886c0f4fd
Author: Campbell Barton
Date:   Sat Aug 27 12:16:13 2022 +1000
Branches: master
https://developer.blender.org/rB578dff786362ba0d1426d1d3d15d579886c0f4fd

Fix assertion when notifiers weren't removed from the notifier queue set

Since [0] notifiers were cleared and left in the queue, while harmless
it meant the call to remove the notifier from the set was redundant.

Now set aside a category to tag notifiers as having been cleared and
skip them entirely.

[0]: 0aaff9a07d3bdf8588cef15d502aeb4fdab22e5e

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

M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm_event_system.cc

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

diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 9d9e0fe8fee..6526b7bec0e 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -321,6 +321,7 @@ typedef struct wmNotifier {
 
 /* category */
 #define NOTE_CATEGORY 0xFF000000
+#define NOTE_CATEGORY_TAG_CLEARED NOTE_CATEGORY
 #define NC_WM (1 << 24)
 #define NC_WINDOW (2 << 24)
 #define NC_WORKSPACE (3 << 24)
diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc
index d6368e73f5a..9cb5194a73b 100644
--- a/source/blender/windowmanager/intern/wm_event_system.cc
+++ b/source/blender/windowmanager/intern/wm_event_system.cc
@@ -91,6 +91,7 @@
 #define USE_GIZMO_MOUSE_PRIORITY_HACK
 
 static void wm_notifier_clear(wmNotifier *note);
+static bool wm_notifier_is_clear(const wmNotifier *note);
 
 static int wm_operator_call_internal(bContext *C,
                                      wmOperatorType *ot,
@@ -287,9 +288,10 @@ void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint typ
   note_test.data = type & NOTE_DATA;
   note_test.subtype = type & NOTE_SUBTYPE;
   note_test.action = type & NOTE_ACTION;
-
   note_test.reference = reference;
 
+  BLI_assert(!wm_notifier_is_clear(&note_test));
+
   if (wm->notifier_queue_set == nullptr) {
     wm->notifier_queue_set = BLI_gset_new_ex(
         note_hash_for_queue_fn, note_cmp_for_queue_fn, __func__, 1024);
@@ -385,6 +387,12 @@ static void wm_notifier_clear(wmNotifier *note)
 {
   /* nullptr the entire notifier, only leaving (`next`, `prev`) members intact. */
   memset(((char *)note) + sizeof(Link), 0, sizeof(*note) - sizeof(Link));
+  note->category = NOTE_CATEGORY_TAG_CLEARED;
+}
+
+static bool wm_notifier_is_clear(const wmNotifier *note)
+{
+  return note->category == NOTE_CATEGORY_TAG_CLEARED;
 }
 
 void wm_event_do_depsgraph(bContext *C, bool is_after_open_file)
@@ -578,6 +586,10 @@ void wm_event_do_notifiers(bContext *C)
   /* The notifiers are sent without context, to keep it clean. */
   wmNotifier *note;
   while ((note = static_cast<wmNotifier *>(BLI_pophead(&wm->notifier_queue)))) {
+    if (wm_notifier_is_clear(note)) {
+      MEM_freeN(note);
+      continue;
+    }
     const bool removed = BLI_gset_remove(wm->notifier_queue_set, note, nullptr);
     BLI_assert(removed);
     UNUSED_VARS_NDEBUG(removed);



More information about the Bf-blender-cvs mailing list