diff options
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 19 |
2 files changed, 23 insertions, 14 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index eefc5e09dbb..483e95f2abb 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1090,13 +1090,12 @@ void scene_update_for_newframe(Main *bmain, Scene *sce, unsigned int lay) SceneRenderLayer *scene_add_render_layer(Scene *sce, const char *name) { SceneRenderLayer *srl; -// int tot= 1 + BLI_countlist(&sce->r.layers); if(!name) name= "RenderLayer"; srl= MEM_callocN(sizeof(SceneRenderLayer), "new render layer"); - strcpy(srl->name, name); + BLI_strncpy(srl->name, name, sizeof(srl->name)); BLI_uniquename(&sce->r.layers, srl, "RenderLayer", '.', offsetof(SceneRenderLayer, name), sizeof(srl->name)); BLI_addtail(&sce->r.layers, srl); @@ -1108,20 +1107,27 @@ SceneRenderLayer *scene_add_render_layer(Scene *sce, const char *name) return srl; } -int scene_remove_render_layer(Main *main, Scene *scene, SceneRenderLayer *srl) +int scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl) { + const int act= BLI_findindex(&scene->r.layers, srl); Scene *sce; - int act= BLI_findindex(&scene->r.layers, srl); - if(BLI_countlist(&scene->r.layers) <= 1) + if (act == -1) { return 0; + } + else if ( (scene->r.layers.first == scene->r.layers.last) && + (scene->r.layers.first == srl)) + { + /* ensure 1 layer is kept */ + return 0; + } BLI_remlink(&scene->r.layers, srl); MEM_freeN(srl); scene->r.actlay= 0; - for(sce = main->scene.first; sce; sce = sce->id.next) { + for(sce = bmain->scene.first; sce; sce = sce->id.next) { if(sce->nodetree) { bNode *node; for(node = sce->nodetree->nodes.first; node; node = node->next) { diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 1bb184c9433..e1fe34d5baf 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -734,7 +734,7 @@ static void rna_RenderSettings_active_layer_set(PointerRNA *ptr, PointerRNA valu if (index != -1) rd->actlay= index; } -static SceneRenderLayer *rna_RenderLayer_add(ID *id, RenderData *UNUSED(rd), const char *name) +static SceneRenderLayer *rna_RenderLayer_new(ID *id, RenderData *UNUSED(rd), const char *name) { Scene *scene= (Scene *)id; SceneRenderLayer *srl= scene_add_render_layer(scene, name); @@ -744,13 +744,16 @@ static SceneRenderLayer *rna_RenderLayer_add(ID *id, RenderData *UNUSED(rd), con return srl; } -static void rna_RenderLayer_remove(ID *id, RenderData *UNUSED(rd), Main *bmain, SceneRenderLayer *srl) +static void rna_RenderLayer_remove(ID *id, RenderData *UNUSED(rd), Main *bmain, ReportList *reports, SceneRenderLayer *srl) { Scene *scene= (Scene *)id; - scene_remove_render_layer(bmain, scene, srl); - - WM_main_add_notifier(NC_SCENE|ND_RENDER_OPTIONS, NULL); + if (!scene_remove_render_layer(bmain, scene, srl)) { + BKE_reportf(reports, RPT_ERROR, "RenderLayer '%s' could not be removed from scene '%s'", srl->name, scene->id.name+2); + } + else { + WM_main_add_notifier(NC_SCENE|ND_RENDER_OPTIONS, NULL); + } } static void rna_RenderSettings_engine_set(PointerRNA *ptr, int value) @@ -2228,17 +2231,17 @@ static void rna_def_render_layers(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_property_ui_text(prop, "Active Render Layer", "Active Render Layer"); RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL); - func= RNA_def_function(srna, "new", "rna_RenderLayer_add"); + func= RNA_def_function(srna, "new", "rna_RenderLayer_new"); RNA_def_function_ui_description(func, "Add a render layer to scene"); RNA_def_function_flag(func, FUNC_USE_SELF_ID); parm= RNA_def_string(func, "name", "RenderLayer", 0, "", "New name for the marker (not unique)"); RNA_def_property_flag(parm, PROP_REQUIRED); - parm= RNA_def_pointer(func, "render_layer", "SceneRenderLayer", "", "Newly created render layer"); + parm= RNA_def_pointer(func, "result", "SceneRenderLayer", "", "Newly created render layer"); RNA_def_function_return(func, parm); func= RNA_def_function(srna, "remove", "rna_RenderLayer_remove"); RNA_def_function_ui_description(func, "Remove a render layer"); - RNA_def_function_flag(func, FUNC_USE_MAIN|FUNC_USE_SELF_ID); + RNA_def_function_flag(func, FUNC_USE_MAIN|FUNC_USE_REPORTS|FUNC_USE_SELF_ID); parm= RNA_def_pointer(func, "layer", "SceneRenderLayer", "", "Timeline marker to remove"); RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); } |