Make freestyle use local Main for temporary objects
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 18 Apr 2013 08:58:21 +0000 (08:58 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 18 Apr 2013 08:58:21 +0000 (08:58 +0000)
This means main database is no longer pollutes with
temporary scene and objects needed for freestyle
render.

Actually, there're few of separated temporary mains
now. Ideally it's better to use single one, but it's
not so much trivial to pass it to all classes. Not
so big deal actually.

Required some changes to blender kernel, to make it
possible to add object to a given main, also to
check on mesh materials for objects in given main.
This is all straightforward changes.

As an additional, solved issue with main database
being infinitely polluted with text blocks created
by create_lineset_handler function.

This fixes:
- #35003: Freestyle crashes if user expands objects in FRS1_Scene
- #35012: ctrl+f12 rendering crashes when using Freestyle

20 files changed:
source/blender/blenkernel/BKE_material.h
source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/object.c
source/blender/collada/collada_utils.cpp
source/blender/editors/curve/editfont.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_constraint.c
source/blender/editors/object/object_hook.c
source/blender/editors/object/object_modifier.c
source/blender/editors/object/object_relations.c
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
source/blender/freestyle/intern/system/PythonInterpreter.h
source/blender/makesrna/intern/rna_main_api.c
source/blender/makesrna/intern/rna_object.c
source/blender/render/intern/source/pipeline.c

index 0bcbbb8576a863d0850dc7aa0f49d709f4beeb67..7c47380f8381cd29b5b8639b740b77de27d1dccc 100644 (file)
@@ -49,7 +49,7 @@ struct Scene;
 void init_def_material(void);
 void BKE_material_free(struct Material *sc); 
 void BKE_material_free_ex(struct Material *ma, int do_id_user);
-void test_object_materials(struct ID *id);
+void test_object_materials(struct Main *bmain, struct ID *id);
 void resize_object_material(struct Object *ob, const short totcol);
 void init_material(struct Material *ma);
 struct Material *BKE_material_add(struct Main *bmain, const char *name);
index da5fa3e819536daf6789866478b1da21f1d475dd..8870355a9198969e44678dc461bca531c0a119ff 100644 (file)
@@ -81,8 +81,8 @@ bool BKE_object_exists_check(struct Object *obtest);
 bool BKE_object_is_in_editmode(struct Object *ob);
 
 struct Object *BKE_object_add_only_object(struct Main *bmain, int type, const char *name);
-struct Object *BKE_object_add(struct Scene *scene, int type);
-void *BKE_object_obdata_add_from_type(int type);
+struct Object *BKE_object_add(struct Main *bmain, struct Scene *scene, int type);
+void *BKE_object_obdata_add_from_type(struct Main *bmain, int type);
 
 struct Object *BKE_object_copy_ex(struct Main *bmain, struct Object *ob, int copy_caches);
 struct Object *BKE_object_copy(struct Object *ob);
index a4f147a4fac62e3819e9830741524e2bdc36dd19..7e70b9d9cd5f25c7880134ab2994128ae253c889 100644 (file)
@@ -568,7 +568,7 @@ void material_append_id(ID *id, Material *ma)
                (*matar)[(*totcol)++] = ma;
 
                id_us_plus((ID *)ma);
-               test_object_materials(id);
+               test_object_materials(G.main, id);
        }
 }
 
@@ -601,7 +601,7 @@ Material *material_pop_id(ID *id, int index_i, int remove_material_slot)
                                        MEM_freeN(*matar);
 
                                        *matar = mat;
-                                       test_object_materials(id);
+                                       test_object_materials(G.main, id);
                                }
 
                                /* decrease mat_nr index */
@@ -712,7 +712,7 @@ void resize_object_material(Object *ob, const short totcol)
        if (ob->actcol > ob->totcol) ob->actcol = ob->totcol;
 }
 
-void test_object_materials(ID *id)
+void test_object_materials(Main *bmain, ID *id)
 {
        /* make the ob mat-array same size as 'ob->data' mat-array */
        Object *ob;
@@ -722,7 +722,7 @@ void test_object_materials(ID *id)
                return;
        }
 
-       for (ob = G.main->object.first; ob; ob = ob->id.next) {
+       for (ob = bmain->object.first; ob; ob = ob->id.next) {
                if (ob->data == id) {
                        resize_object_material(ob, *totcol);
                }
@@ -768,7 +768,7 @@ void assign_material_id(ID *id, Material *ma, short act)
        if (ma)
                id_us_plus((ID *)ma);
 
-       test_object_materials(id);
+       test_object_materials(G.main, id);
 }
 
 void assign_material(Object *ob, Material *ma, short act, int assign_type)
@@ -855,7 +855,7 @@ void assign_material(Object *ob, Material *ma, short act, int assign_type)
 
        if (ma)
                id_us_plus((ID *)ma);
-       test_object_materials(ob->data);
+       test_object_materials(G.main, ob->data);
 }
 
 /* XXX - this calls many more update calls per object then are needed, could be optimized */
index 31c2758795dc4fb981e98ee6bd2cf195182db828..0d662711df0287f0256775443c9266c87fbf4f39 100644 (file)
@@ -841,7 +841,7 @@ void BKE_mesh_assign_object(Object *ob, Mesh *me)
                id_us_plus((ID *)me);
        }
        
-       test_object_materials((ID *)me);
+       test_object_materials(G.main, (ID *)me);
 
        test_object_modifiers(ob);
 }
index 538cead5d5b6591629263d3d99b163c83eeb81ba..fb950b180a9b69a835c53e6894d3ab18a5fc8fc7 100644 (file)
@@ -845,19 +845,19 @@ bool BKE_object_exists_check(Object *obtest)
 
 /* *************************************************** */
 
-void *BKE_object_obdata_add_from_type(int type)
+void *BKE_object_obdata_add_from_type(Main *bmain, int type)
 {
        switch (type) {
-               case OB_MESH:      return BKE_mesh_add(G.main, "Mesh");
-               case OB_CURVE:     return BKE_curve_add(G.main, "Curve", OB_CURVE);
-               case OB_SURF:      return BKE_curve_add(G.main, "Surf", OB_SURF);
-               case OB_FONT:      return BKE_curve_add(G.main, "Text", OB_FONT);
-               case OB_MBALL:     return BKE_mball_add(G.main, "Meta");
-               case OB_CAMERA:    return BKE_camera_add(G.main, "Camera");
-               case OB_LAMP:      return BKE_lamp_add(G.main, "Lamp");
-               case OB_LATTICE:   return BKE_lattice_add(G.main, "Lattice");
-               case OB_ARMATURE:  return BKE_armature_add(G.main, "Armature");
-               case OB_SPEAKER:   return BKE_speaker_add(G.main, "Speaker");
+               case OB_MESH:      return BKE_mesh_add(bmain, "Mesh");
+               case OB_CURVE:     return BKE_curve_add(bmain, "Curve", OB_CURVE);
+               case OB_SURF:      return BKE_curve_add(bmain, "Surf", OB_SURF);
+               case OB_FONT:      return BKE_curve_add(bmain, "Text", OB_FONT);
+               case OB_MBALL:     return BKE_mball_add(bmain, "Meta");
+               case OB_CAMERA:    return BKE_camera_add(bmain, "Camera");
+               case OB_LAMP:      return BKE_lamp_add(bmain, "Lamp");
+               case OB_LATTICE:   return BKE_lattice_add(bmain, "Lattice");
+               case OB_ARMATURE:  return BKE_armature_add(bmain, "Armature");
+               case OB_SPEAKER:   return BKE_speaker_add(bmain, "Speaker");
                case OB_EMPTY:     return NULL;
                default:
                        printf("BKE_object_obdata_add_from_type: Internal error, bad type: %d\n", type);
@@ -972,16 +972,16 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
 
 /* general add: to scene, with layer from area and default name */
 /* creates minimum required data, but without vertices etc. */
-Object *BKE_object_add(struct Scene *scene, int type)
+Object *BKE_object_add(Main *bmain, Scene *scene, int type)
 {
        Object *ob;
        Base *base;
        char name[MAX_ID_NAME];
 
        BLI_strncpy(name, get_obdata_defname(type), sizeof(name));
-       ob = BKE_object_add_only_object(G.main, type, name);
+       ob = BKE_object_add_only_object(bmain, type, name);
 
-       ob->data = BKE_object_obdata_add_from_type(type);
+       ob->data = BKE_object_obdata_add_from_type(bmain, type);
 
        ob->lay = scene->lay;
        
index 9aa1f7b97147cad689adc1958c3abf3a1e08d6b1..6a18ac09615bc5b95cd517d5c0f371dd9b60a989 100644 (file)
@@ -129,7 +129,7 @@ Object *bc_add_object(Scene *scene, int type, const char *name)
 {
        Object *ob = BKE_object_add_only_object(G.main, type, name);
 
-       ob->data = BKE_object_obdata_add_from_type(type);
+       ob->data = BKE_object_obdata_add_from_type(G.main, type);
        ob->lay = scene->lay;
        DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
 
index 16e7e0fde4abc8cc18972dbf0a6e291a789bb484..f990afcc044d31ffe41f1dc5515ed771d6e590a2 100644 (file)
@@ -56,6 +56,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_font.h"
 #include "BKE_library.h"
+#include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_report.h"
 
@@ -439,6 +440,7 @@ void FONT_OT_file_paste(wmOperatorType *ot)
 
 static void txt_add_object(bContext *C, TextLine *firstline, int totline, float offset[3])
 {
+       Main *bmain = CTX_data_main(C);
        Scene *scene = CTX_data_scene(C);
        Curve *cu;
        Object *obedit;
@@ -447,7 +449,7 @@ static void txt_add_object(bContext *C, TextLine *firstline, int totline, float
        int nchars = 0, a;
        float rot[3] = {0.f, 0.f, 0.f};
        
-       obedit = BKE_object_add(scene, OB_FONT);
+       obedit = BKE_object_add(bmain, scene, OB_FONT);
        base = scene->basact;
 
        /* seems to assume view align ? TODO - look into this, could be an operator option */
index 9e70fe550bc930d301a1c22c4479c988a5c9ede4..efc4acd7c4f24aec275810036b815a23eb6c9e61 100644 (file)
@@ -537,7 +537,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        if (matmap) MEM_freeN(matmap);
        
        /* other mesh users */
-       test_object_materials((ID *)me);
+       test_object_materials(bmain, (ID *)me);
        
        /* free temp copy of destination shapekeys (if applicable) */
        if (nkey) {
index 7ededa50a1586d4fd2eac19039119515891b69de..ffdfe0531273be385387f6c57ea7f9e30294e189 100644 (file)
@@ -376,7 +376,7 @@ Object *ED_object_add_type(bContext *C, int type, const float loc[3], const floa
                ED_object_editmode_exit(C, EM_FREEDATA | EM_FREEUNDO | EM_WAITCURSOR | EM_DO_UNDO);  /* freedata, and undo */
 
        /* deselects all, sets scene->basact */
-       ob = BKE_object_add(scene, type);
+       ob = BKE_object_add(bmain, scene, type);
        BASACT->lay = ob->lay = layer;
        /* editor level activate, notifiers */
        ED_base_object_activate(C, BASACT);
index 3e66c4ca1107c06c78903a366b5cfe6e0c4c6bf0..2ba5fb24292d09c3082b8e8d0bd0272cf19783f0 100644 (file)
@@ -1572,12 +1572,13 @@ static short get_new_constraint_target(bContext *C, int con_type, Object **tar_o
        
        /* if still not found, add a new empty to act as a target (if allowed) */
        if ((found == 0) && (add)) {
+               Main *bmain = CTX_data_main(C);
                Scene *scene = CTX_data_scene(C);
                Base *base = BASACT, *newbase = NULL;
                Object *obt;
                
                /* add new target object */
-               obt = BKE_object_add(scene, OB_EMPTY);
+               obt = BKE_object_add(bmain, scene, OB_EMPTY);
                
                /* set layers OK */
                newbase = BASACT;
index e3a679e8bc30fbd26fe575baa968cace5c9e02f9..69ad3f3225fea3ff0a0d77675e816288acef5e88 100644 (file)
@@ -438,12 +438,12 @@ static int hook_op_edit_poll(bContext *C)
        return 0;
 }
 
-static Object *add_hook_object_new(Scene *scene, Object *obedit)
+static Object *add_hook_object_new(Main *bmain, Scene *scene, Object *obedit)
 {
        Base *base, *basedit;
        Object *ob;
 
-       ob = BKE_object_add(scene, OB_EMPTY);
+       ob = BKE_object_add(bmain, scene, OB_EMPTY);
        
        basedit = BKE_scene_base_find(scene, obedit);
        base = BKE_scene_base_find(scene, ob);
@@ -473,7 +473,7 @@ static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob
 
        if (mode == OBJECT_ADDHOOK_NEWOB && !ob) {
                
-               ob = add_hook_object_new(scene, obedit);
+               ob = add_hook_object_new(bmain, scene, obedit);
                
                /* transform cent to global coords for loc */
                mul_v3_m4v3(ob->loc, obedit->obmat, cent);
index e89c581a7b6a36a27b732a5e1d3c35b097da888a..7d9feec6d7817419be9034c1a80fba56947a05c0 100644 (file)
@@ -464,7 +464,7 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), Main *bmain, Scene *
        if (totvert == 0) return 0;
 
        /* add new mesh */
-       obn = BKE_object_add(scene, OB_MESH);
+       obn = BKE_object_add(bmain, scene, OB_MESH);
        me = obn->data;
        
        me->totvert = totvert;
@@ -1721,8 +1721,7 @@ static void skin_armature_bone_create(Object *skin_ob,
        }
 }
 
-static Object *modifier_skin_armature_create(struct Scene *scene,
-                                             Object *skin_ob)
+static Object *modifier_skin_armature_create(Main *bmain, Scene *scene, Object *skin_ob)
 {
        BLI_bitmap edges_visited;
        DerivedMesh *deform_dm;
@@ -1745,7 +1744,7 @@ static Object *modifier_skin_armature_create(struct Scene *scene,
                             NULL,
                             me->totvert);
        
-       arm_ob = BKE_object_add(scene, OB_ARMATURE);
+       arm_ob = BKE_object_add(bmain, scene, OB_ARMATURE);
        BKE_object_transform_copy(arm_ob, skin_ob);
        arm = arm_ob->data;
        arm->layer = 1;
@@ -1815,7 +1814,7 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op)
        }
 
        /* create new armature */
-       arm_ob = modifier_skin_armature_create(scene, ob);
+       arm_ob = modifier_skin_armature_create(bmain, scene, ob);
 
        /* add a modifier to connect the new armature to the mesh */
        arm_md = (ArmatureModifierData *)modifier_new(eModifierType_Armature);
index 9ed57adf207fbaa4175786de31a2625aa29d7852..9838c99a81bc08761ab34a0979b42c89a27e7133 100644 (file)
@@ -344,7 +344,7 @@ static int make_proxy_exec(bContext *C, wmOperator *op)
                char name[MAX_ID_NAME + 4];
                
                /* Add new object for the proxy */
-               newob = BKE_object_add(scene, OB_EMPTY);
+               newob = BKE_object_add(bmain, scene, OB_EMPTY);
 
                BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name + 2);
 
@@ -1459,7 +1459,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
                                                ob_dst->data = id;
 
                                                /* if amount of material indices changed: */
-                                               test_object_materials(ob_dst->data);
+                                               test_object_materials(bmain, ob_dst->data);
 
                                                DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
                                                break;
index dd75e4d0dd54d74f6599f45c736497afeaf498d4..2d3fc20f92952c51dfa069cf54bdad4d8f565b83 100644 (file)
@@ -64,6 +64,8 @@ namespace Freestyle {
 
 BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : StrokeRenderer()
 {
+       memset(&_freestyle_bmain, 0, sizeof(Main));
+
        // TEMPORARY - need a  texture manager
        _textureManager = new BlenderTextureManager;
        _textureManager->load();
@@ -77,7 +79,7 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
 
        char name[22];
        BLI_snprintf(name, sizeof(name), "FRS%d_%s", render_count, re->scene->id.name + 2);
-       freestyle_scene = BKE_scene_add(G.main, name);
+       freestyle_scene = BKE_scene_add(&_freestyle_bmain, name);
        freestyle_scene->r.cfra = old_scene->r.cfra;
        freestyle_scene->r.mode = old_scene->r.mode &
                                  ~(R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR | R_BORDER);
@@ -120,10 +122,10 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
        SceneRenderLayer *srl = (SceneRenderLayer *)freestyle_scene->r.layers.first;
        srl->layflag = SCE_LAY_SOLID | SCE_LAY_ZTRA;
 
-       BKE_scene_set_background(G.main, freestyle_scene);
+       BKE_scene_set_background(&_freestyle_bmain, freestyle_scene);
 
        // Camera
-       Object *object_camera = BKE_object_add(freestyle_scene, OB_CAMERA);
+       Object *object_camera = BKE_object_add(&_freestyle_bmain, freestyle_scene, OB_CAMERA);
 
        Camera *camera = (Camera *)object_camera->data;
        camera->type = CAM_ORTHO;
@@ -144,7 +146,7 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
        freestyle_scene->camera = object_camera;
 
        // Material
-       material = BKE_material_add(G.main, "stroke_material");
+       material = BKE_material_add(&_freestyle_bmain, "stroke_material");
        material->mode |= MA_VERTEXCOLP;
        material->mode |= MA_TRANSP;
        material->mode |= MA_SHLESS;
@@ -178,12 +180,12 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer()
 #endif
                switch (ob->type) {
                case OB_MESH:
-                       BKE_libblock_free(&G.main->object, ob);
-                       BKE_libblock_free(&G.main->mesh, data);
+                       BKE_libblock_free(&_freestyle_bmain.object, ob);
+                       BKE_libblock_free(&_freestyle_bmain.mesh, data);
                        break;
                case OB_CAMERA:
-                       BKE_libblock_free(&G.main->object, ob);
-                       BKE_libblock_free(&G.main->camera, data);
+                       BKE_libblock_free(&_freestyle_bmain.object, ob);
+                       BKE_libblock_free(&_freestyle_bmain.camera, data);
                        freestyle_scene->camera = NULL;
                        break;
                default:
@@ -193,9 +195,11 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer()
        BLI_freelistN(&freestyle_scene->base);
 
        // release material
-       BKE_libblock_free(&G.main->mat, material);
+       BKE_libblock_free(&_freestyle_bmain.mat, material);
+
+       //BKE_scene_set_background(&_freestyle_bmain, old_scene);
 
-       BKE_scene_set_background(G.main, old_scene);
+       BKE_scene_unlink(&_freestyle_bmain, freestyle_scene, NULL);
 }
 
 float BlenderStrokeRenderer::get_stroke_vertex_z(void) const
@@ -279,7 +283,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
 
                //me = Mesh.New()
 #if 0
-               Object *object_mesh = BKE_object_add(freestyle_scene, OB_MESH);
+               Object *object_mesh = BKE_object_add(&_freestyle_bmain, freestyle_scene, OB_MESH);
 #else
                Object *object_mesh = NewMesh();
 #endif
@@ -294,7 +298,7 @@ void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
                mesh->mat = (Material **)MEM_mallocN(1 * sizeof(Material *), "MaterialList");
                mesh->mat[0] = material;
                mesh->totcol = 1;
-               test_object_materials((ID *)mesh);
+               test_object_materials((Main *) &_freestyle_bmain, (ID *)mesh);
 #else
                assign_material(object_mesh, material, object_mesh->totcol + 1);
                object_mesh->actcol = object_mesh->totcol;
@@ -481,9 +485,9 @@ Object *BlenderStrokeRenderer::NewMesh() const
        /* XXX this is for later review, for now we start names with 27 (DEL) 
           to allow ignoring them in DAG_ids_check_recalc() */
        BLI_snprintf(name, MAX_ID_NAME, "%c0%08xOB", 27, mesh_id);
-       ob = BKE_object_add_only_object(G.main, OB_MESH, name);
+       ob = BKE_object_add_only_object((Main *) &_freestyle_bmain, OB_MESH, name);
        BLI_snprintf(name, MAX_ID_NAME, "%c0%08xME", 27, mesh_id);
-       ob->data = BKE_mesh_add(G.main, name);
+       ob->data = BKE_mesh_add((Main *) &_freestyle_bmain, name);
        ob->lay = 1;
 
        base = BKE_scene_base_add(freestyle_scene, ob);
@@ -511,7 +515,7 @@ Render *BlenderStrokeRenderer::RenderScene(Render *re)
 
        Render *freestyle_render = RE_NewRender(freestyle_scene->id.name);
 
-       RE_RenderFreestyleStrokes(freestyle_render, G.main, freestyle_scene);
+       RE_RenderFreestyleStrokes(freestyle_render, &_freestyle_bmain, freestyle_scene);
        return freestyle_render;
 }
 
index f4af5e3aba0b1c4511e69e6c18dc190e0f844b49..4a80e8ce7e2b160e636fb42351b7b5ee98eee61f 100644 (file)
@@ -32,6 +32,8 @@ extern "C" {
 #include "DNA_material_types.h"
 #include "DNA_scene_types.h"
 
+#include "BKE_main.h"
+
 #include "render_types.h"
 }
 
@@ -52,6 +54,7 @@ public:
        Render *RenderScene(Render *re);
 
 protected:
+       Main _freestyle_bmain;
        Scene *old_scene;
        Scene *freestyle_scene;
        Material *material;
index 56d12612dbca269a3f6158769673bd3e678a5fce..5db258c23fdf9edcb7aca4d03225c13565b87080 100644 (file)
@@ -212,11 +212,11 @@ static char *escape_quotes(char *name)
        return s;
 }
 
-static Text *create_lineset_handler(char *layer_name, char *lineset_name)
+static Text *create_lineset_handler(Main *bmain, char *layer_name, char *lineset_name)
 {
        char *s1 = escape_quotes(layer_name);
        char *s2 = escape_quotes(lineset_name);
-       Text *text = BKE_text_add(G.main, lineset_name);
+       Text *text = BKE_text_add(bmain, lineset_name);
        BKE_text_write(text, "import parameter_editor; parameter_editor.process('");
        BKE_text_write(text, s1);
        BKE_text_write(text, "', '");
@@ -294,7 +294,7 @@ static bool test_edge_type_conditions(struct edge_type_condition *conditions,
        return true;
 }
 
-static void prepare(Render *re, SceneRenderLayer *srl)
+static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl)
 {
        // load mesh
        re->i.infostr = "Freestyle: Mesh loading";
@@ -370,7 +370,7 @@ static void prepare(Render *re, SceneRenderLayer *srl)
                                        cout << "  " << layer_count+1 << ": " << lineset->name << " - " <<
                                                lineset->linestyle->id.name + 2 << endl;
                                }
-                               Text *text = create_lineset_handler(srl->name, lineset->name);
+                               Text *text = create_lineset_handler(bmain, srl->name, lineset->name);
                                controller->InsertStyleModule(layer_count, lineset->name, text);
                                controller->toggleLayer(layer_count, true);
                                if (!(lineset->selection & FREESTYLE_SEL_EDGE_TYPES) || !lineset->edge_types) {
@@ -581,7 +581,9 @@ void FRS_init_stroke_rendering(Render *re)
 
 Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl)
 {
+       Main bmain = {0};
        Render *freestyle_render = NULL;
+       Text *text, *next_text;
 
        RenderMonitor monitor(re);
        controller->setRenderMonitor(&monitor);
@@ -598,7 +600,7 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl)
        //   - add style modules
        //   - set parameters
        //   - compute view map
-       prepare(re, srl);
+       prepare(&bmain, re, srl);
 
        if (re->test_break(re->tbh)) {
                controller->CloseFile();
@@ -626,6 +628,14 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl)
                freestyle_render->result = NULL;
        }
 
+       // Free temp main (currently only text blocks are stored there)
+       for (text = (Text *) bmain.text.first; text; text = next_text) {
+               next_text = (Text *) text->id.next;
+
+               BKE_text_unlink(&bmain, text);
+               BKE_libblock_free(&bmain.text, text);
+       }
+
        return freestyle_render;
 }
 
index c54546b3dddc8b6ab1d61600b505e5e4a767140a..7c271252a32c59a1d5bdcd818a2c2bd554fafd33 100644 (file)
@@ -83,11 +83,11 @@ public:
                int status = BPY_filepath_exec(_context, fn, reports);
 #else
                int status;
-               Text *text = BKE_text_load(G.main, fn, G.main->name);
+               Text *text = BKE_text_load(&_freestyle_bmain, fn, G.main->name);
                if (text) {
                        status = BPY_text_exec(_context, text, reports, false);
-                       BKE_text_unlink(G.main, text);
-                       BKE_libblock_free(&G.main->text, text);
+                       BKE_text_unlink(&_freestyle_bmain, text);
+                       BKE_libblock_free(&_freestyle_bmain.text, text);
                }
                else {
                        BKE_reportf(reports, RPT_ERROR, "Cannot open file: %s", fn);
@@ -151,6 +151,7 @@ public:
 
 private:
        bContext *_context;
+       Main _freestyle_bmain;
 
        void initPath()
        {
@@ -160,7 +161,7 @@ private:
                vector<string> pathnames;
                StringUtils::getPathName(_path, "", pathnames);
 
-               struct Text *text = BKE_text_add(G.main, "tmp_freestyle_initpath.txt");
+               struct Text *text = BKE_text_add(&_freestyle_bmain, "tmp_freestyle_initpath.txt");
                string cmd = "import sys\n";
                txt_insert_buf(text, const_cast<char*>(cmd.c_str()));
 
@@ -177,8 +178,8 @@ private:
                BPY_text_exec(_context, text, NULL, false);
 
                // cleaning up
-               BKE_text_unlink(G.main, text);
-               BKE_libblock_free(&G.main->text, text);
+               BKE_text_unlink(&_freestyle_bmain, text);
+               BKE_libblock_free(&_freestyle_bmain.text, text);
 
                //PyRun_SimpleString("from Freestyle import *");
                _initialized = true;
index b9fb269638a4ceddef028385c20b0fc54ba9775c..5d554f4393c1f510c37f3da811f40bb506cfe13b 100644 (file)
@@ -198,7 +198,7 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char
        id_us_min(&ob->id);
 
        ob->data = data;
-       test_object_materials(ob->data);
+       test_object_materials(bmain, ob->data);
        
        return ob;
 }
@@ -465,7 +465,7 @@ Mesh *rna_Main_meshes_new_from_object(
        }
 
        /* make sure materials get updated in objects */
-       test_object_materials(&tmpmesh->id);
+       test_object_materials(bmain, &tmpmesh->id);
 
        return tmpmesh;
 }
index 0eb7ab8e58103a6d13637b1c89b0047d37076caf..c611e0fdd949468dbac3f3afe67de7f4a471299c 100644 (file)
@@ -181,6 +181,7 @@ EnumPropertyItem object_axis_items[] = {
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
 #include "BKE_effect.h"
+#include "BKE_global.h"
 #include "BKE_key.h"
 #include "BKE_object.h"
 #include "BKE_material.h"
@@ -396,7 +397,7 @@ static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value)
                }
 
                ob->data = id;
-               test_object_materials(id);
+               test_object_materials(G.main, id);
 
                if (GS(id->name) == ID_CU)
                        BKE_curve_type_test(ob);
index 7f2c3b5ad04e3155563abeebb51865ef28ac49c4..4e9d185becffefb0a2a1f368b820872d08e90e86 100644 (file)
@@ -1058,7 +1058,7 @@ static void threaded_tile_processor(Render *re)
 
 #ifdef WITH_FREESTYLE
 static void add_freestyle(Render *re);
-static void free_all_freestyle_renders(Scene *scene);
+static void free_all_freestyle_renders(void);
 #endif
 
 /* currently only called by preview renders and envmap */
@@ -1075,7 +1075,7 @@ void RE_TileProcessor(Render *re)
                if (!re->test_break(re->tbh)) {
                        add_freestyle(re);
        
-                       free_all_freestyle_renders(re->scene);
+                       free_all_freestyle_renders();
                        
                        re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime;
                        re->stats_draw(re->sdh, &re->i);
@@ -1653,7 +1653,7 @@ static void composite_freestyle_renders(Render *re, int sample)
 }
 
 /* releases temporary scenes and renders for Freestyle stroke rendering */
-static void free_all_freestyle_renders(Scene *scene)
+static void free_all_freestyle_renders(void)
 {
        Render *re1, *freestyle_render;
        LinkData *link;
@@ -1662,7 +1662,6 @@ static void free_all_freestyle_renders(Scene *scene)
                for (link = (LinkData *)re1->freestyle_renders.first; link; link = link->next) {
                        if (link->data) {
                                freestyle_render = (Render *)link->data;
-                               BKE_scene_unlink(G.main, freestyle_render->scene, scene);
                                RE_FreeRender(freestyle_render);
                        }
                }
@@ -1918,7 +1917,7 @@ static void do_render_composite_fields_blur_3d(Render *re)
        }
 
 #ifdef WITH_FREESTYLE
-       free_all_freestyle_renders(re->scene);
+       free_all_freestyle_renders();
 #endif
 
        /* weak... the display callback wants an active renderlayer pointer... */