diff --git a/panda/src/egg/eggData.cxx b/panda/src/egg/eggData.cxx index aa79f89336..1585176b8b 100644 --- a/panda/src/egg/eggData.cxx +++ b/panda/src/egg/eggData.cxx @@ -296,15 +296,6 @@ pre_write() { textures.uniquify_trefs(); textures.sort_by_tref(); - // Now put them all back at the head of the file, after any initial - // comment records. - iterator ci = begin(); - while (ci != end() && (*ci)->is_of_type(EggComment::get_class_type())) { - ++ci; - } - - textures.insert_textures(this, ci); - // Do the same thing with the materials. EggMaterialCollection materials; materials.extract_materials(this); @@ -312,6 +303,14 @@ pre_write() { materials.collapse_equivalent_materials(~0, this); materials.uniquify_mrefs(); materials.sort_by_mref(); + + // Now put them all back at the head of the file, after any initial + // comment records. + iterator ci = begin(); + while (ci != end() && (*ci)->is_of_type(EggComment::get_class_type())) { + ++ci; + } + textures.insert_textures(this, ci); materials.insert_materials(this, ci); // Also make sure that the vertex pools are uniquely named. This diff --git a/panda/src/egg/eggGroupNode.cxx b/panda/src/egg/eggGroupNode.cxx index 4abe111495..09a6132d4a 100644 --- a/panda/src/egg/eggGroupNode.cxx +++ b/panda/src/egg/eggGroupNode.cxx @@ -961,6 +961,7 @@ r_resolve_externals(const DSearchPath &searchpath, //////////////////////////////////////////////////////////////////// void EggGroupNode:: prepare_add_child(EggNode *node) { + nassertv(node != (EggNode *)NULL); // Make sure the node is not already a child of some other group. nassertv(node->get_parent() == NULL); nassertv(node->get_depth() == 0); @@ -983,6 +984,7 @@ prepare_add_child(EggNode *node) { //////////////////////////////////////////////////////////////////// void EggGroupNode:: prepare_remove_child(EggNode *node) { + nassertv(node != (EggNode *)NULL); // Make sure the node is in fact a child of this group. nassertv(node->get_parent() == this); nassertv(node->get_depth() == get_depth() + 1); diff --git a/panda/src/egg/eggMaterialCollection.cxx b/panda/src/egg/eggMaterialCollection.cxx index 16c267e337..ebce3df10b 100644 --- a/panda/src/egg/eggMaterialCollection.cxx +++ b/panda/src/egg/eggMaterialCollection.cxx @@ -76,10 +76,10 @@ extract_materials(EggGroupNode *node) { // Access: Public // Description: Adds a series of EggMaterial nodes to the beginning of // the indicated node to reflect each of the materials in -// the collection. Returns the number of material nodes -// added. +// the collection. Returns an iterator representing the +// first position after the newly inserted materials. //////////////////////////////////////////////////////////////////// -int EggMaterialCollection:: +EggGroupNode::iterator EggMaterialCollection:: insert_materials(EggGroupNode *node) { return insert_materials(node, node->begin()); } @@ -89,19 +89,20 @@ insert_materials(EggGroupNode *node) { // Access: Public // Description: Adds a series of EggMaterial nodes to the beginning of // the indicated node to reflect each of the materials in -// the collection. Returns the number of material nodes -// added. +// the collection. Returns an iterator representing the +// first position after the newly inserted materials. //////////////////////////////////////////////////////////////////// -int EggMaterialCollection:: +EggGroupNode::iterator EggMaterialCollection:: insert_materials(EggGroupNode *node, EggGroupNode::iterator position) { OrderedMaterials::iterator oti; for (oti = _ordered_materials.begin(); oti != _ordered_materials.end(); ++oti) { - node->insert(position, (*oti).p()); + EggMaterial *material = (*oti); + position = node->insert(position, material); } - return size(); + return position; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggMaterialCollection.h b/panda/src/egg/eggMaterialCollection.h index 156f8276e5..35ff5537ad 100644 --- a/panda/src/egg/eggMaterialCollection.h +++ b/panda/src/egg/eggMaterialCollection.h @@ -50,8 +50,8 @@ public: void clear(); int extract_materials(EggGroupNode *node); - int insert_materials(EggGroupNode *node); - int insert_materials(EggGroupNode *node, EggGroupNode::iterator position); + EggGroupNode::iterator insert_materials(EggGroupNode *node); + EggGroupNode::iterator insert_materials(EggGroupNode *node, EggGroupNode::iterator position); int find_used_materials(EggNode *node); void remove_unused_materials(EggNode *node); diff --git a/panda/src/egg/eggNameUniquifier.cxx b/panda/src/egg/eggNameUniquifier.cxx index 32620dc14e..6f751500ac 100644 --- a/panda/src/egg/eggNameUniquifier.cxx +++ b/panda/src/egg/eggNameUniquifier.cxx @@ -75,7 +75,9 @@ uniquify(EggNode *node) { EggGroupNode::iterator ci; for (ci = group->begin(); ci != group->end(); ++ci) { - uniquify(*ci); + EggNode *child = (*ci); + nassertv(child != (EggNode *)NULL); + uniquify(child); } } } diff --git a/panda/src/egg/eggTextureCollection.cxx b/panda/src/egg/eggTextureCollection.cxx index 7077870966..301b4e6c0f 100644 --- a/panda/src/egg/eggTextureCollection.cxx +++ b/panda/src/egg/eggTextureCollection.cxx @@ -76,10 +76,10 @@ extract_textures(EggGroupNode *node) { // Access: Public // Description: Adds a series of EggTexture nodes to the beginning of // the indicated node to reflect each of the textures in -// the collection. Returns the number of texture nodes -// added. +// the collection. Returns an iterator representing the +// first position after the newly inserted textures. //////////////////////////////////////////////////////////////////// -int EggTextureCollection:: +EggGroupNode::iterator EggTextureCollection:: insert_textures(EggGroupNode *node) { return insert_textures(node, node->begin()); } @@ -89,19 +89,20 @@ insert_textures(EggGroupNode *node) { // Access: Public // Description: Adds a series of EggTexture nodes to the beginning of // the indicated node to reflect each of the textures in -// the collection. Returns the number of texture nodes -// added. +// the collection. Returns an iterator representing the +// first position after the newly inserted textures. //////////////////////////////////////////////////////////////////// -int EggTextureCollection:: +EggGroupNode::iterator EggTextureCollection:: insert_textures(EggGroupNode *node, EggGroupNode::iterator position) { OrderedTextures::iterator oti; for (oti = _ordered_textures.begin(); oti != _ordered_textures.end(); ++oti) { - node->insert(position, (*oti).p()); + EggTexture *texture = (*oti); + position = node->insert(position, texture); } - return size(); + return position; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggTextureCollection.h b/panda/src/egg/eggTextureCollection.h index d81f959874..08aa848e2c 100644 --- a/panda/src/egg/eggTextureCollection.h +++ b/panda/src/egg/eggTextureCollection.h @@ -50,8 +50,8 @@ public: void clear(); int extract_textures(EggGroupNode *node); - int insert_textures(EggGroupNode *node); - int insert_textures(EggGroupNode *node, EggGroupNode::iterator position); + EggGroupNode::iterator insert_textures(EggGroupNode *node); + EggGroupNode::iterator insert_textures(EggGroupNode *node, EggGroupNode::iterator position); int find_used_textures(EggNode *node); void remove_unused_textures(EggNode *node);