浏览代码

fix crash from bam files

David Rose 20 年之前
父节点
当前提交
4f6c012c77

+ 22 - 0
panda/src/gobj/qpgeomVertexArrayFormat.cxx

@@ -594,6 +594,27 @@ complete_pointers(TypedWritable **p_list, BamReader *manager) {
   return pi;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: qpGeomVertexArrayFormat::finalize
+//       Access: Public, Virtual
+//  Description: Called by the BamReader to perform any final actions
+//               needed for setting up the object after all objects
+//               have been read and all pointers have been completed.
+////////////////////////////////////////////////////////////////////
+void qpGeomVertexArrayFormat::
+finalize(BamReader *manager) {
+  // Now we can build up the _columns_by_name index.  We have to wait
+  // until finalize(), since the index is based on the nested name
+  // pointer within each column, which might not be available at the
+  // time complete_pointers() is called.
+  _columns_by_name.clear();
+  Columns::iterator ci;
+  for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
+    qpGeomVertexColumn *column = (*ci);
+    _columns_by_name.insert(ColumnsByName::value_type(column->get_name(), column));
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: qpGeomVertexArrayFormat::make_from_bam
 //       Access: Protected, Static
@@ -611,6 +632,7 @@ make_from_bam(const FactoryParams &params) {
 
   parse_params(params, scan, manager);
   object->fillin(scan, manager);
+  manager->register_finalize(object);
 
   return object;
 }

+ 2 - 0
panda/src/gobj/qpgeomVertexArrayFormat.h

@@ -156,6 +156,8 @@ public:
   virtual void write_datagram(BamWriter *manager, Datagram &dg);
   virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
 
+  virtual void finalize(BamReader *manager);
+
 protected:
   static TypedWritable *make_from_bam(const FactoryParams &params);
   void fillin(DatagramIterator &scan, BamReader *manager);

+ 1 - 0
panda/src/gobj/qpgeomVertexData.cxx

@@ -445,6 +445,7 @@ copy_from(const qpGeomVertexData *source, bool keep_data_objects) {
           dest_format->get_array(dest_i);
         const qpGeomVertexColumn *dest_column = 
           dest_array_format->get_column(source_column->get_name());
+        nassertv(dest_column != (const qpGeomVertexColumn *)NULL);
 
         if (dest_column->is_bytewise_equivalent(*source_column)) {
           // We can do a quick bytewise copy.