From bb83bdf89123690e99ef36afd24a93246685dc68 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 26 Jan 2014 16:06:47 +0100 Subject: Fix T38366: export collada crash - if you set a keyframe Don't assume all objects have a valid animdata... --- source/blender/collada/AnimationExporter.cpp | 53 +++++++++++++++------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'source/blender/collada/AnimationExporter.cpp') diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index 559b180189f..7e90f05b519 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -1279,19 +1279,20 @@ char *AnimationExporter::extract_transform_name(char *rna_path) //find keyframes of all the objects animations void AnimationExporter::find_frames(Object *ob, std::vector &fra) { - FCurve *fcu = (FCurve *)ob->adt->action->curves.first; - - for (; fcu; fcu = fcu->next) { + if (ob->adt && ob->adt->action) { + FCurve *fcu = (FCurve *)ob->adt->action->curves.first; - for (unsigned int i = 0; i < fcu->totvert; i++) { - float f = fcu->bezt[i].vec[1][0]; - if (std::find(fra.begin(), fra.end(), f) == fra.end()) - fra.push_back(f); + for (; fcu; fcu = fcu->next) { + for (unsigned int i = 0; i < fcu->totvert; i++) { + float f = fcu->bezt[i].vec[1][0]; + if (std::find(fra.begin(), fra.end(), f) == fra.end()) + fra.push_back(f); + } } - } - // keep the keys in ascending order - std::sort(fra.begin(), fra.end()); + // keep the keys in ascending order + std::sort(fra.begin(), fra.end()); + } } @@ -1371,24 +1372,26 @@ void AnimationExporter::find_rotation_frames(Object *ob, std::vector &fra void AnimationExporter::find_frames(Object *ob, std::vector &fra, const char *prefix, const char *tm_name) { - FCurve *fcu = (FCurve *)ob->adt->action->curves.first; - - for (; fcu; fcu = fcu->next) { - if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix))) - continue; - - char *name = extract_transform_name(fcu->rna_path); - if (!strcmp(name, tm_name)) { - for (unsigned int i = 0; i < fcu->totvert; i++) { - float f = fcu->bezt[i].vec[1][0]; - if (std::find(fra.begin(), fra.end(), f) == fra.end()) - fra.push_back(f); + if (ob->adt && ob->adt->action) { + FCurve *fcu = (FCurve *)ob->adt->action->curves.first; + + for (; fcu; fcu = fcu->next) { + if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix))) + continue; + + char *name = extract_transform_name(fcu->rna_path); + if (!strcmp(name, tm_name)) { + for (unsigned int i = 0; i < fcu->totvert; i++) { + float f = fcu->bezt[i].vec[1][0]; + if (std::find(fra.begin(), fra.end(), f) == fra.end()) + fra.push_back(f); + } } } - } - // keep the keys in ascending order - std::sort(fra.begin(), fra.end()); + // keep the keys in ascending order + std::sort(fra.begin(), fra.end()); + } } void AnimationExporter::write_bone_animation(Object *ob_arm, Bone *bone) -- cgit v1.2.3