From 4f6c012c778325bd01a91fa2003823e7eb2ffa53 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 20 Apr 2005 16:48:04 +0000 Subject: [PATCH] fix crash from bam files --- panda/src/gobj/qpgeomVertexArrayFormat.cxx | 22 ++++++++++++++++++++++ panda/src/gobj/qpgeomVertexArrayFormat.h | 2 ++ panda/src/gobj/qpgeomVertexData.cxx | 1 + 3 files changed, 25 insertions(+) diff --git a/panda/src/gobj/qpgeomVertexArrayFormat.cxx b/panda/src/gobj/qpgeomVertexArrayFormat.cxx index de1ad27b8f..d74e75ccb2 100644 --- a/panda/src/gobj/qpgeomVertexArrayFormat.cxx +++ b/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 ¶ms) { parse_params(params, scan, manager); object->fillin(scan, manager); + manager->register_finalize(object); return object; } diff --git a/panda/src/gobj/qpgeomVertexArrayFormat.h b/panda/src/gobj/qpgeomVertexArrayFormat.h index 68627b0e91..91d13f2d05 100644 --- a/panda/src/gobj/qpgeomVertexArrayFormat.h +++ b/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 ¶ms); void fillin(DatagramIterator &scan, BamReader *manager); diff --git a/panda/src/gobj/qpgeomVertexData.cxx b/panda/src/gobj/qpgeomVertexData.cxx index 48dd242879..f5545b61e1 100644 --- a/panda/src/gobj/qpgeomVertexData.cxx +++ b/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.