Fix for properly unlinking target object pointers when objects are deleted
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Mon, 29 Nov 2010 21:24:55 +0000 (21:24 +0000)
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>
Mon, 29 Nov 2010 21:24:55 +0000 (21:24 +0000)
from scenes.

source/blender/blenkernel/BKE_linestyle.h
source/blender/blenkernel/intern/linestyle.c
source/blender/blenkernel/intern/object.c
source/blender/freestyle/FRS_freestyle.h
source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp

index 2e68ab38ecd48f38263d1dc88950cd18bf490be2..ebbfe7c55598147b658469c1f76126a06efbc6a9 100644 (file)
@@ -39,6 +39,7 @@
 #define LS_MODIFIER_TYPE_THICKNESS  3
 
 struct Main;
+struct Object;
 
 FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main);
 void FRS_free_linestyle(FreestyleLineStyle *linestyle);
@@ -58,4 +59,6 @@ void FRS_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineSt
 void FRS_list_modifier_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase);
 char *FRS_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp);
 
+void FRS_unlink_linestyle_target_object(FreestyleLineStyle *linestyle, struct Object *ob);
+
 #endif
index 4b12473eda24c5c97a57c0807d6e1f0f2dd1b5d6..f6f8378cebc70458599bb69d0d4e616d6d44cb61 100644 (file)
@@ -368,3 +368,30 @@ char *FRS_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *c
 found:
        return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", m->name);
 }
+
+void FRS_unlink_linestyle_target_object(FreestyleLineStyle *linestyle, struct Object *ob)
+{
+       LineStyleModifier *m;
+
+       for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
+               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+                       if (((LineStyleColorModifier_DistanceFromObject *)m)->target == ob) {
+                               ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL;
+                       }
+               }
+       }
+       for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next) {
+               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+                       if (((LineStyleAlphaModifier_DistanceFromObject *)m)->target == ob) {
+                               ((LineStyleAlphaModifier_DistanceFromObject *)m)->target = NULL;
+                       }
+               }
+       }
+       for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next) {
+               if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
+                       if (((LineStyleThicknessModifier_DistanceFromObject *)m)->target == ob) {
+                               ((LineStyleThicknessModifier_DistanceFromObject *)m)->target = NULL;
+                       }
+               }
+       }
+}
index fe557dfefa0b6d3f4a1a3702f48bae1af7e037bb..79818ba679917fd3e47dd89c27a49b380f63d622 100644 (file)
 
 #include "GPU_material.h"
 
+#include "FRS_freestyle.h"
+
 /* Local function protos */
 static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul);
 
@@ -577,6 +579,14 @@ void unlink_object(Object *ob)
                                        }
                                SEQ_END
                        }
+
+                       {
+                               SceneRenderLayer *srl;
+
+                               for (srl= sce->r.layers.first; srl; srl= srl->next) {
+                                       FRS_unlink_target_object(&srl->freestyleConfig, ob);
+                               }
+                       }
                }
 
                sce= sce->id.next;
index 8252e932215fcd84d3da2124409b2018b91dd10b..ae8adb86c1cd3a11f76d5b5a2272e1605a2f7150 100644 (file)
@@ -39,6 +39,7 @@ extern "C" {
        #include "DNA_scene_types.h"
        
        #include "BKE_context.h"
+       #include "BKE_object.h"
        
        extern Scene *freestyle_scene;
        extern float freestyle_viewpoint[3];
@@ -71,6 +72,8 @@ extern "C" {
        short FRS_get_active_lineset_index(FreestyleConfig *config);
        void FRS_set_active_lineset_index(FreestyleConfig *config, short index);
 
+       void FRS_unlink_target_object(FreestyleConfig *config, struct Object *ob);
+
 #ifdef __cplusplus
 }
 #endif
index 5fb472865e66db13da12db44f2460e05a1d706a1..7cb7349f61defc950629568e3f8b81bfb669cc6d 100644 (file)
@@ -519,6 +519,15 @@ extern "C" {
                }
        }
 
+       void FRS_unlink_target_object(FreestyleConfig *config, Object *ob)
+       {
+               FreestyleLineSet *lineset;
+
+               for(lineset=(FreestyleLineSet *)config->linesets.first; lineset; lineset=lineset->next) {
+                       FRS_unlink_linestyle_target_object(lineset->linestyle, ob);
+               }
+       }
+
 #ifdef __cplusplus
 }
 #endif