Fix #31089: collada file crashing on importing file with unknown/unsupported animatio...
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 2 May 2012 18:11:09 +0000 (18:11 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 2 May 2012 18:11:09 +0000 (18:11 +0000)
source/blender/collada/AnimationImporter.cpp
source/blender/collada/AnimationImporter.h

index 6a66f1fb8172e8fdc7c40b0e58bd0ca8a56c819c..cf815920b5758646ee7ac3786a22622d9c8454db 100644 (file)
@@ -438,6 +438,16 @@ void AnimationImporter::modify_fcurve(std::vector<FCurve*>* curves, const char*
        }
 }
 
+void AnimationImporter::unused_fcurve(std::vector<FCurve*>* curves)
+{
+       // when an error happens and we can't actually use curve remove it from unused_curves
+       std::vector<FCurve*>::iterator it;
+       for (it = curves->begin(); it != curves->end(); it++) {
+               FCurve *fcu = *it;
+               unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu), unused_curves.end());
+       }
+}
+
 void AnimationImporter::find_frames( std::vector<float>* frames, std::vector<FCurve*>* curves)
 {
        std::vector<FCurve*>::iterator iter;
@@ -499,6 +509,7 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation *
                        modify_fcurve(curves, rna_path, -1 );
                        break;
                default:
+                       unused_fcurve(curves);
                        fprintf(stderr, "AnimationClass %d is not supported for %s.\n",
                                binding->animationClass, loc ? "TRANSLATE" : "SCALE");
                                }
@@ -534,10 +545,13 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation *
                        else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
                                modify_fcurve(curves, rna_path, 2 );
                        }
+                       else
+                               unused_fcurve(curves);
                        break;
                case COLLADAFW::AnimationList::AXISANGLE:
                        // TODO convert axis-angle to quat? or XYZ?
                default:
+                       unused_fcurve(curves);
                        fprintf(stderr, "AnimationClass %d is not supported for ROTATE transformation.\n",
                                binding->animationClass);
                                }
@@ -553,9 +567,11 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation *
 
                        }
                        }*/
+                       unused_fcurve(curves);
                        break;
                case COLLADAFW::Transformation::SKEW:
                case COLLADAFW::Transformation::LOOKAT:
+                       unused_fcurve(curves);
                        fprintf(stderr, "Animation of SKEW and LOOKAT transformations is not supported yet.\n");
                        break;
        }
@@ -591,6 +607,7 @@ void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& list
                        break;
 
                default:
+                       unused_fcurve(&animcurves);
                        fprintf(stderr, "AnimationClass %d is not supported for %s.\n",
                                bindings[j].animationClass, "COLOR" );
                }
index 362b288dbb44c5970671fceffd78ed83259fc8f7..6324853d91c80d837b2e1881f70dbe3fe56a3249 100644 (file)
@@ -165,6 +165,7 @@ public:
        int setAnimType ( const COLLADAFW::Animatable * prop, int type, int addition);
        
        void modify_fcurve(std::vector<FCurve*>* curves, const char* rna_path, int array_index );
+       void unused_fcurve(std::vector<FCurve*>* curves );
        // prerequisites:
        // animlist_map - map animlist id -> animlist
        // curve_map - map anim id -> curve(s)