diff --git a/pandatool/src/mayaegg/mayaNodeTree.cxx b/pandatool/src/mayaegg/mayaNodeTree.cxx index 31f54946af..537652ca15 100755 --- a/pandatool/src/mayaegg/mayaNodeTree.cxx +++ b/pandatool/src/mayaegg/mayaNodeTree.cxx @@ -191,6 +191,23 @@ get_node(int n) const { return _nodes[n]; } +//////////////////////////////////////////////////////////////////// +// Function: MayaNodeTree::clear +// Access: Public +// Description: Resets the entire tree in preparation for +// repopulating with a new scene. +//////////////////////////////////////////////////////////////////// +void MayaNodeTree:: +clear() { + _root = new MayaNodeDesc; + _fps = 0.0; + _egg_data = (EggData *)NULL; + _egg_root = (EggGroupNode *)NULL; + _skeleton_node = (EggGroupNode *)NULL; + _nodes_by_path.clear(); + _nodes.clear(); +} + //////////////////////////////////////////////////////////////////// // Function: MayaNodeTree::clear_egg // Access: Public diff --git a/pandatool/src/mayaegg/mayaNodeTree.h b/pandatool/src/mayaegg/mayaNodeTree.h index 24c7175e9b..486d277bff 100755 --- a/pandatool/src/mayaegg/mayaNodeTree.h +++ b/pandatool/src/mayaegg/mayaNodeTree.h @@ -41,6 +41,7 @@ public: int get_num_nodes() const; MayaNodeDesc *get_node(int n) const; + void clear(); void clear_egg(EggData *egg_data, EggGroupNode *egg_root, EggGroupNode *skeleton_node); EggGroup *get_egg_group(MayaNodeDesc *node_desc); diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index f9cb2da74e..d7de76f0db 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -181,6 +181,13 @@ convert_file(const Filename &filename) { << "Maya is not available.\n"; return false; } + + // We must ensure our Maya pointers are cleared before we reset the + // Maya scene, because resetting the Maya scene will invalidate all + // the Maya pointers we are holding and cause a crash if we try to + // free them later. + clear(); + if (!_maya->read(filename)) { mayaegg_cat.error() << "Unable to read " << filename << "\n"; @@ -220,8 +227,8 @@ get_input_units() { bool MayaToEggConverter:: convert_maya(bool from_selection) { _from_selection = from_selection; - _textures.clear(); - _shaders.clear(); + + clear(); if (!open_api()) { mayaegg_cat.error() @@ -364,11 +371,26 @@ open_api() { //////////////////////////////////////////////////////////////////// void MayaToEggConverter:: close_api() { - // We have to clear the shaders before we release the Maya API. - _shaders.clear(); + // We have to clear the shaders, at least, before we release the + // Maya API. + clear(); _maya.clear(); } +//////////////////////////////////////////////////////////////////// +// Function: MayaToEggConverter::clear +// Access: Public +// Description: Frees all of the Maya pointers kept within this +// object, in preparation for loading a new scene or +// releasing the Maya API. +//////////////////////////////////////////////////////////////////// +void MayaToEggConverter:: +clear() { + _tree.clear(); + _textures.clear(); + _shaders.clear(); +} + //////////////////////////////////////////////////////////////////// // Function: MayaToEggConverter::convert_flip // Access: Private @@ -561,6 +583,7 @@ process_model_node(MayaNodeDesc *node_desc) { MFnDagNode dag_node(dag_path, &status); if (!status) { status.perror("MFnDagNode constructor"); + mayaegg_cat.error() << dag_path.fullPathName() << "\n"; return false; } diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index b2602323a5..e702a455b5 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -80,6 +80,7 @@ public: void close_api(); private: + void clear(); bool convert_flip(double start_frame, double end_frame, double frame_inc, double output_frame_rate);