fix for some errors when unlinking.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 1 Oct 2012 07:54:37 +0000 (07:54 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 1 Oct 2012 07:54:37 +0000 (07:54 +0000)
- movieclip unlink didn't clear node ID pointers from the scene (leaving dangling pointers).
- mask datablock unlink was clearning references from scene nodes twice.

source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/mask.c
source/blender/blenkernel/intern/movieclip.c
source/blender/nodes/intern/node_common.c

index 6ad2ad924e23c2e6c03577ff689fbfc856405985..acd6f120f937dc3df07ed81da1421f34c5bfd05c 100644 (file)
@@ -475,6 +475,8 @@ struct bNodeSocket *node_group_add_extern_socket(struct bNodeTree *ntree, ListBa
 void register_node_type_frame(struct bNodeTreeType *ttype);
 void register_node_type_reroute(struct bNodeTreeType *ttype);
 
+void BKE_node_tree_unlink_id_cb(void *calldata, struct ID *owner_id, struct bNodeTree *ntree);
+
 /* ************** SHADER NODES *************** */
 
 struct ShadeInput;
index 3564071334c7a32400a0bd9e01f89a51ea16cd09..cacbf988ba993f9e40b2beff8bd4fb5108f75c67 100644 (file)
@@ -916,19 +916,6 @@ void BKE_mask_free_nolib(Mask *mask)
        BKE_mask_layer_free_list(&mask->masklayers);
 }
 
-
-static void ntree_unlink_mask_cb(void *calldata, struct ID *UNUSED(owner_id), struct bNodeTree *ntree)
-{
-       ID *id = (ID *)calldata;
-       bNode *node;
-
-       for (node = ntree->nodes.first; node; node = node->next) {
-               if (node->id == id) {
-                       node->id = NULL;
-               }
-       }
-}
-
 void BKE_mask_free(Main *bmain, Mask *mask)
 {
        bScreen *scr;
@@ -975,21 +962,11 @@ void BKE_mask_free(Main *bmain, Mask *mask)
                        }
                        SEQ_END
                }
-
-
-               if (scene->nodetree) {
-                       bNode *node;
-                       for (node = scene->nodetree->nodes.first; node; node = node->next) {
-                               if (node->id == &mask->id) {
-                                       node->id = NULL;
-                               }
-                       }
-               }
        }
 
        {
                bNodeTreeType *treetype = ntreeGetType(NTREE_COMPOSIT);
-               treetype->foreach_nodetree(bmain, (void *)mask, &ntree_unlink_mask_cb);
+               treetype->foreach_nodetree(bmain, (void *)mask, &BKE_node_tree_unlink_id_cb);
        }
 
        /* free mask data */
index 386e4163fd294f6f2213ef1e333598c336d9a602..8a2bdd81da22042dc3365102e01f0ec5456d2e8d 100644 (file)
@@ -52,6 +52,7 @@
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
 #include "DNA_movieclip_types.h"
+#include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_view3d_types.h"
@@ -71,6 +72,7 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_movieclip.h"
+#include "BKE_node.h"
 #include "BKE_image.h"  /* openanim */
 #include "BKE_tracking.h"
 
@@ -1326,6 +1328,11 @@ void BKE_movieclip_unlink(Main *bmain, MovieClip *clip)
                }
        }
 
+       {
+               bNodeTreeType *treetype = ntreeGetType(NTREE_COMPOSIT);
+               treetype->foreach_nodetree(bmain, (void *)clip, &BKE_node_tree_unlink_id_cb);
+       }
+
        clip->id.us = 0;
 }
 
index a61cf00d81c3e662c7d56cba97c0617711ce8752..301dea22c17bfa26b37751d0c62289d286cdcf09 100644 (file)
@@ -650,3 +650,15 @@ void ntree_update_reroute_nodes(bNodeTree *ntree)
                if (node->type == NODE_REROUTE && !node->done)
                        node_reroute_inherit_type_recursive(ntree, node);
 }
+
+void BKE_node_tree_unlink_id_cb(void *calldata, struct ID *UNUSED(owner_id), struct bNodeTree *ntree)
+{
+       ID *id = (ID *)calldata;
+       bNode *node;
+
+       for (node = ntree->nodes.first; node; node = node->next) {
+               if (node->id == id) {
+                       node->id = NULL;
+               }
+       }
+}