Fix T45423: depsgraph: crash in IDDepsNode::tag_update

Two issues fixed in this commit:

- Clearing or adding animation via python should ensure relations are valid.
- Animation component animation data might be null caused by removing animation
  from python.
This commit is contained in:
Sergey Sharybin 2015-07-14 11:19:27 +02:00
parent 9c80e52a89
commit 82740cd282
2 changed files with 21 additions and 4 deletions

@ -250,8 +250,8 @@ void IDDepsNode::tag_update(Depsgraph *graph)
bool do_component_tag = comp_node->type != DEPSNODE_TYPE_ANIMATION;
if (comp_node->type == DEPSNODE_TYPE_ANIMATION) {
AnimData *adt = BKE_animdata_from_id(id);
BLI_assert(adt != NULL);
if (adt->recalc & ADT_RECALC_ANIM) {
/* Animation data might be null if relations are tagged for update. */
if (adt != NULL && (adt->recalc & ADT_RECALC_ANIM)) {
do_component_tag = true;
}
}

@ -85,6 +85,8 @@ EnumPropertyItem id_type_items[] = {
#ifdef RNA_RUNTIME
#include "DNA_anim_types.h"
#include "BKE_font.h"
#include "BKE_idprop.h"
#include "BKE_library.h"
@ -331,6 +333,19 @@ static void rna_ID_user_clear(ID *id)
id->flag &= ~LIB_FAKEUSER;
}
static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
{
AnimData *adt = BKE_animdata_add_id(id);
DAG_relations_tag_update(bmain);
return adt;
}
static void rna_ID_animation_data_free(ID *id, Main *bmain)
{
BKE_animdata_free(id);
DAG_relations_tag_update(bmain);
}
static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
IDProperty *prop = (IDProperty *)ptr->data;
@ -835,12 +850,14 @@ static void rna_def_ID(BlenderRNA *brna)
RNA_def_function_ui_description(func, "Clear the user count of a datablock so its not saved, "
"on reload the data will be removed");
func = RNA_def_function(srna, "animation_data_create", "BKE_animdata_add_id");
func = RNA_def_function(srna, "animation_data_create", "rna_ID_animation_data_create");
RNA_def_function_flag(func, FUNC_USE_MAIN);
RNA_def_function_ui_description(func, "Create animation data to this ID, note that not all ID types support this");
parm = RNA_def_pointer(func, "anim_data", "AnimData", "", "New animation data or NULL");
RNA_def_function_return(func, parm);
func = RNA_def_function(srna, "animation_data_clear", "BKE_animdata_free");
func = RNA_def_function(srna, "animation_data_clear", "rna_ID_animation_data_free");
RNA_def_function_flag(func, FUNC_USE_MAIN);
RNA_def_function_ui_description(func, "Clear animation on this this ID");
func = RNA_def_function(srna, "update_tag", "rna_ID_update_tag");