Cleanup: WM_main_remove_notifier_reference
authorCampbell Barton <ideasman42@gmail.com>
Mon, 4 May 2015 02:40:38 +0000 (12:40 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 4 May 2015 06:01:20 +0000 (16:01 +1000)
Assumed the `reference` pointer is an ID, currently true, but may not always be.
Add a callback specifically for this purpose since cleaning up notifiers and space-types are different operations.

source/blender/blenkernel/BKE_library.h
source/blender/blenkernel/intern/library.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_init_exit.c

index f00bd0754a31447152cfc6c0177295222b78e897..6ecc955e26c052b47275aa7f01249771cfd3aea1 100644 (file)
@@ -109,6 +109,7 @@ struct ID *BKE_libblock_find_name(const short type, const char *name) ATTR_WARN_
 
 void BKE_library_callback_free_window_manager_set(void (*func)(struct bContext *, struct wmWindowManager *));
 void BKE_library_callback_free_notifier_reference_set(void (*func)(const void *));
+void BKE_library_callback_free_editor_id_reference_set(void (*func)(const struct ID *));
 
 /* use when "" is given to new_id() */
 #define ID_FALLBACK_NAME N_("Untitled")
index ccc373b6eb4fa513be2e946d084156b66126be91..42856e820629188b5b05c4aaa1aacc676100f0dc 100644 (file)
@@ -877,6 +877,12 @@ void BKE_library_callback_free_notifier_reference_set(void (*func)(const void *)
        free_notifier_reference_cb = func;
 }
 
+static void (*free_editor_id_reference_cb)(const ID *) = NULL;
+
+void BKE_library_callback_free_editor_id_reference_set(void (*func)(const ID *))
+{
+       free_editor_id_reference_cb = func;
+}
 
 static void animdata_dtar_clear_cb(ID *UNUSED(id), AnimData *adt, void *userdata)
 {
@@ -1034,8 +1040,13 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, bool do_id_user)
        /* avoid notifying on removed data */
        BKE_main_lock(bmain);
 
-       if (free_notifier_reference_cb)
+       if (free_notifier_reference_cb) {
                free_notifier_reference_cb(id);
+       }
+
+       if (free_editor_id_reference_cb) {
+               free_editor_id_reference_cb(id);
+       }
 
        BLI_remlink(lb, id);
 
index dbeea80ba82b8a3b532856c11d172d938750f77f..d4148a56dd2474eb2c83f3940d003ea915398206 100644 (file)
@@ -175,6 +175,7 @@ bool        WM_modal_tweak_exit(const struct wmEvent *event, int tweak_event);
 void           WM_event_add_notifier(const struct bContext *C, unsigned int type, void *reference);
 void           WM_main_add_notifier(unsigned int type, void *reference);
 void           WM_main_remove_notifier_reference(const void *reference);
+void           WM_main_remove_editor_id_reference(const struct ID *id);
 
                        /* reports */
 void        WM_report(const struct bContext *C, ReportType type, const char *message);
index c883b37f6c5dbd973cc636afb0ae4ff013876f56..f054c5a43c1771cc8c27c4b8c137755202712870 100644 (file)
@@ -218,7 +218,6 @@ void WM_main_remove_notifier_reference(const void *reference)
 {
        Main *bmain = G.main;
        wmWindowManager *wm = bmain->wm.first;
-       bScreen *sc;
 
        if (wm) {
                wmNotifier *note, *note_next;
@@ -233,6 +232,12 @@ void WM_main_remove_notifier_reference(const void *reference)
                        }
                }
        }
+}
+
+void WM_main_remove_editor_id_reference(const ID *id)
+{
+       Main *bmain = G.main;
+       bScreen *sc;
 
        for (sc = bmain->screen.first; sc; sc = sc->id.next) {
                ScrArea *sa;
@@ -244,7 +249,7 @@ void WM_main_remove_notifier_reference(const void *reference)
                                if (sl->spacetype == SPACE_OUTLINER) {
                                        SpaceOops *so = (SpaceOops *)sl;
 
-                                       ED_outliner_id_unref(so, (ID *)reference);
+                                       ED_outliner_id_unref(so, id);
                                }
                        }
                }
index add09aa4c1fcb26e2a0f097a134eb206e3b350fa..7ca82c0c03ae958669bbe36d2d699063ec0e946d 100644 (file)
@@ -151,6 +151,7 @@ void WM_init(bContext *C, int argc, const char **argv)
 
        BKE_library_callback_free_window_manager_set(wm_close_and_free);   /* library.c */
        BKE_library_callback_free_notifier_reference_set(WM_main_remove_notifier_reference);   /* library.c */
+       BKE_library_callback_free_editor_id_reference_set(WM_main_remove_editor_id_reference);   /* library.c */
        BKE_blender_callback_test_break_set(wm_window_testbreak); /* blender.c */
        DAG_editors_update_cb(ED_render_id_flush_update, ED_render_scene_update); /* depsgraph.c */