diff options
author | Julian Eisel <julian@blender.org> | 2020-08-19 13:32:11 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-08-19 13:37:59 +0300 |
commit | 5cc08510e0a636ea99eb753cb0ff65861d5e4813 (patch) | |
tree | 667463aca1ed00983f419e8648ba92fc1222a832 | |
parent | 8cbfc4c76ed7747111e387863ad511939d389d87 (diff) |
RNA: Validate scene/view-layer combination for statistics query
Users may input an invalid scene/view-layer combination via Python. We
can easily detect that and fail gracefully.
Besides checking input parameters in RNA, also assert the
scene/view-layer combination is valid in lower level Depsgraph lookup
function (called by statistics query).
-rw-r--r-- | source/blender/blenkernel/BKE_scene.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 12 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_scene.c | 12 |
3 files changed, 25 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index e3bd57e75e3..3ab923f05f6 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -110,6 +110,8 @@ void BKE_toolsettings_free(struct ToolSettings *toolsettings); struct Scene *BKE_scene_duplicate(struct Main *bmain, struct Scene *sce, eSceneCopyMethod type); void BKE_scene_groups_relink(struct Scene *sce); +struct Scene *BKE_scene_find_from_view_layer(const struct Main *bmain, + const struct ViewLayer *layer); struct Scene *BKE_scene_find_from_collection(const struct Main *bmain, const struct Collection *collection); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 6f1cca619ff..1dc51c9ddae 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1129,6 +1129,17 @@ int BKE_scene_base_iter_next( return iter->phase; } +Scene *BKE_scene_find_from_view_layer(const Main *bmain, const ViewLayer *layer) +{ + for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { + if (BLI_findindex(&scene->view_layers, layer) != -1) { + return scene; + } + } + + return NULL; +} + Scene *BKE_scene_find_from_collection(const Main *bmain, const Collection *collection) { for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { @@ -2246,6 +2257,7 @@ static Depsgraph **scene_get_depsgraph_p(Main *bmain, { BLI_assert(scene != NULL); BLI_assert(view_layer != NULL); + BLI_assert(BKE_scene_find_from_view_layer(bmain, view_layer) == scene); /* Make sure hash itself exists. */ if (allocate_ghash_entry) { BKE_scene_ensure_depsgraph_hash(scene); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 0936995429c..3ec7963a81e 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -926,8 +926,18 @@ static void rna_Scene_volume_update(Main *UNUSED(bmain), Scene *UNUSED(scene), P static const char *rna_Scene_statistics_string_get(Scene *scene, Main *bmain, + ReportList *reports, ViewLayer *view_layer) { + if (BKE_scene_find_from_view_layer(bmain, view_layer) != scene) { + BKE_reportf(reports, + RPT_ERROR, + "View Layer '%s' not found in scene '%s'", + view_layer->name, + scene->id.name + 2); + return ""; + } + return ED_info_statistics_string(bmain, scene, view_layer); } @@ -7680,7 +7690,7 @@ void RNA_def_scene(BlenderRNA *brna) /* Statistics */ func = RNA_def_function(srna, "statistics", "rna_Scene_statistics_string_get"); - RNA_def_function_flag(func, FUNC_USE_MAIN); + RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS); parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "View Layer", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); parm = RNA_def_string(func, "statistics", NULL, 0, "Statistics", ""); |