Fish
01-01-2009 19:24:47
When attempting to get a TreeLoader3D iterator using
The following patch prevents this error from occurring by testing if trees->pageGridList is empty. If the GridList is empty then the hasMore flag is set to false and the function returns. This won't prevent all fatal errors with this iterator but I think it needs to be stated in the documentation, "Be sure to test hasMoreElements() before using any other members of TreeIterator3D" to minimize the risk of a fatal exception. I think that statement is pretty obvious to most of us but I included the documentation patch below so that it is explicit.
-Fish
TreeIterator3D TreeLoader3D::getTrees()
and the process enters the TreeIterator3D::TreeIterator3D(TreeLoader3D *trees)
constructor, it could be possible that the trees->pageGridList
is empty and an STL assertion thrown when currentGrid->second
is attempted in currentTreeList = &trees->_getGridPage(currentGrid->second, currentX, currentZ);
The following patch prevents this error from occurring by testing if trees->pageGridList is empty. If the GridList is empty then the hasMore flag is set to false and the function returns. This won't prevent all fatal errors with this iterator but I think it needs to be stated in the documentation, "Be sure to test hasMoreElements() before using any other members of TreeIterator3D" to minimize the risk of a fatal exception. I think that statement is pretty obvious to most of us but I included the documentation patch below so that it is explicit.
-Fish
Index: TreeLoader3D.cpp
===================================================================
--- TreeLoader3D.cpp (revision 2589)
+++ TreeLoader3D.cpp (working copy)
@@ -488,7 +488,15 @@
{
TreeIterator3D::trees = trees;
- //Setup iterators
+ // Test if the GridList has anything in it
+ if(trees->pageGridList.empty())
+ {
+ // If not, set hasMore to false and return.
+ hasMore = false;
+ return;
+ }
+
+ //Setup iterators
currentGrid = trees->pageGridList.begin();
currentX = 0; currentZ = 0;
currentTreeList = &trees->_getGridPage(currentGrid->second, currentX, currentZ);
Index: TreeLoader3D.h
===================================================================
--- TreeLoader3D.h (revision 2589)
+++ TreeLoader3D.h (working copy)
@@ -105,6 +105,8 @@
to this TreeLoader3D fairly efficiently.
\see The TreeIterator class documentation for more info.
+ \warning Be sure to test TreeIterator3D::hasMoreElements() before calling other members of the
+ TreeIterator3D class.
*/
TreeIterator3D getTrees();