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).
This commit is contained in:
parent
8cbfc4c76e
commit
5cc08510e0
Notes:
blender-bot
2023-02-14 05:04:52 +01:00
Referenced by commit 7aeaf5da0e
, Fix crash when accessing `view_layer.depsgraph` through BPY
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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", "");
|
||||
|
|
Loading…
Reference in New Issue