Parcourir la source

fix crash loading multiple maya files in one sessions

David Rose il y a 22 ans
Parent
commit
70f8a82a0d

+ 17 - 0
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

+ 1 - 0
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);

+ 27 - 4
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;
   }
 

+ 1 - 0
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);