RNA: Make is clear that `Scene` parameter of `update` callback may be NULL.

There are cases where there is no way to ensure we do have/know about an
active scene. Further more, this should not be required to perform
'real' updates on data, only to perform additional special handling in
current scene (mostly related to editing tools, UI, etc.).

This pointer is actually almost never used in practice, and half of its current
 usages are fairly close to abuse of the system (like calls to
`ED_gpencil_tag_scene_gpencil` or `BKE_rigidbody_cache_reset`).

This commit ensures that the few places using this 'active scene' pointer are
safely handling the `NULL` case, and clearly document the fact that a
NULL scene pointer is valid.
This commit is contained in:
Bastien Montagne 2021-09-27 14:57:00 +02:00
parent b077f0684e
commit 5949d598bc
Notes: blender-bot 2023-02-14 06:42:54 +01:00
Referenced by commit 91b4c1841a, Fix T92272: Rigid Body Copy to Selected "Margin" crash
8 changed files with 31 additions and 12 deletions

View File

@ -2206,6 +2206,7 @@ void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
rna_property_update(C, CTX_data_main(C), CTX_data_scene(C), ptr, prop);
}
/* NOTE: `scene` pointer may be NULL. */
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
{
rna_property_update(NULL, bmain, scene, ptr, prop);

View File

@ -161,7 +161,9 @@ static void rna_ImageUser_update(Main *bmain, Scene *scene, PointerRNA *ptr)
ImageUser *iuser = ptr->data;
ID *id = ptr->owner_id;
BKE_image_user_frame_calc(NULL, iuser, scene->r.cfra);
if (scene != NULL) {
BKE_image_user_frame_calc(NULL, iuser, scene->r.cfra);
}
if (id) {
if (GS(id->name) == ID_NT) {

View File

@ -44,11 +44,20 @@ typedef struct IDProperty IDProperty;
/* Function Callbacks */
typedef void (*UpdateFunc)(struct Main *main, struct Scene *scene, struct PointerRNA *ptr);
/** Update callback for an RNA property.
*
* \note This is NOT called automatically when writing into the property, it needs to be called
* manually (through #RNA_property_update or #RNA_property_update_main) when needed.
*
* \param bmain: the Main data-base to which `ptr` data belongs.
* \param active_scene: The current active scene (may be NULL in some cases).
* \param ptr: The RNA pointer data to update. */
typedef void (*UpdateFunc)(struct Main *bmain, struct Scene *active_scene, struct PointerRNA *ptr);
typedef void (*ContextPropUpdateFunc)(struct bContext *C,
struct PointerRNA *ptr,
struct PropertyRNA *prop);
typedef void (*ContextUpdateFunc)(struct bContext *C, struct PointerRNA *ptr);
typedef int (*EditableFunc)(struct PointerRNA *ptr, const char **r_info);
typedef int (*ItemEditableFunc)(struct PointerRNA *ptr, int index);
typedef struct IDProperty **(*IDPropertiesFunc)(struct PointerRNA *ptr);

View File

@ -3742,7 +3742,7 @@ static void rna_Node_image_layer_update(Main *bmain, Scene *scene, PointerRNA *p
rna_Node_update(bmain, scene, ptr);
if (scene->nodetree != NULL) {
if (scene != NULL && scene->nodetree != NULL) {
ntreeCompositUpdateRLayers(scene->nodetree);
}
}
@ -3914,7 +3914,7 @@ static const EnumPropertyItem *rna_Node_view_layer_itemf(bContext *UNUSED(C),
static void rna_Node_view_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
rna_Node_update(bmain, scene, ptr);
if (scene->nodetree != NULL) {
if (scene != NULL && scene->nodetree != NULL) {
ntreeCompositUpdateRLayers(scene->nodetree);
}
}
@ -4349,7 +4349,7 @@ static void rna_ShaderNodeScript_update(Main *bmain, Scene *scene, PointerRNA *p
{
bNodeTree *ntree = (bNodeTree *)ptr->owner_id;
bNode *node = (bNode *)ptr->data;
RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
RenderEngineType *engine_type = (scene != NULL) ? RE_engines_find(scene->r.engine) : NULL;
if (engine_type && engine_type->update_script_node) {
/* auto update node */

View File

@ -215,9 +215,10 @@ static void rna_RigidBodyWorld_constraints_collection_update(Main *bmain,
static void rna_RigidBodyOb_reset(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
{
RigidBodyWorld *rbw = scene->rigidbody_world;
BKE_rigidbody_cache_reset(rbw);
if (scene != NULL) {
RigidBodyWorld *rbw = scene->rigidbody_world;
BKE_rigidbody_cache_reset(rbw);
}
}
static void rna_RigidBodyOb_shape_update(Main *bmain, Scene *scene, PointerRNA *ptr)

View File

@ -676,7 +676,9 @@ static void rna_ToolSettings_snap_mode_set(struct PointerRNA *ptr, int value)
/* Grease Pencil update cache */
static void rna_GPencil_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
{
ED_gpencil_tag_scene_gpencil(scene);
if (scene != NULL) {
ED_gpencil_tag_scene_gpencil(scene);
}
}
static void rna_Gpencil_extend_selection(bContext *C, PointerRNA *UNUSED(ptr))

View File

@ -130,7 +130,9 @@ const EnumPropertyItem rna_enum_symmetrize_direction_items[] = {
static void rna_GPencil_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
{
/* mark all grease pencil datablocks of the scene */
ED_gpencil_tag_scene_gpencil(scene);
if (scene != NULL) {
ED_gpencil_tag_scene_gpencil(scene);
}
}
const EnumPropertyItem rna_enum_particle_edit_disconnected_hair_brush_items[] = {

View File

@ -906,7 +906,7 @@ static void rna_GPencil_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UN
static void rna_SpaceView3D_camera_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
View3D *v3d = (View3D *)(ptr->data);
if (v3d->scenelock) {
if (v3d->scenelock && scene != NULL) {
wmWindowManager *wm = bmain->wm.first;
scene->camera = v3d->camera;
@ -1540,7 +1540,9 @@ static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr)
static void rna_SpaceImageEditor_mode_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
{
ED_space_image_paint_update(bmain, bmain->wm.first, scene);
if (scene != NULL) {
ED_space_image_paint_update(bmain, bmain->wm.first, scene);
}
}
static void rna_SpaceImageEditor_show_stereo_set(PointerRNA *ptr, int value)