Pcl: OctreeIteratorBase bug in comparison operators ==/!=

Created on 9 Nov 2017  路  4Comments  路  Source: PointCloudLibrary/pcl

There is a bug in octree_iterator.h for the operator==() and operator!=() which can be found between the lines 136 and 151.

The boolean output of operator==() is inequal to the negation of the boolean output of operator!=().

Your Environment

  • Operating System and version: All
  • Compiler: All
  • PCL Version: Latest ( and most likely all previous ones )

Expected Behavior

(itA==itB) == !(itA!=itB);

Current Behavior

(itA==itB) != !(itA!=itB);

Possible Solution

A quick fix might be this ( at least with that the code below will work ).

        bool operator==(const OctreeIteratorBase& other) const
        {
             return !this->operator!=(other);
         }

However, the problem seems to be more deeply nested inside the implementation of OctreeIteratorBase. It appears wrong that with octree.breadth_end() we get an iterator which is not related at all to the underlying octree. In other words

auto aIt = octreeA.breadth_end();
auto bIt = octreeB.breadth_end();

The members of iterator aIt and bIt are absolutely identical.

Code to Reproduce

       // works as expected
    auto it = octree.breadth_begin();
    const auto it_end = octree.breadth_end();

    for (it; it != it_end; it++)
    {
        cout << "Hello" << endl;
    }
       // stuck in an endless loop
    auto it = octree.breadth_begin();
    const auto it_end = octree.breadth_end();
        while (true)
    {
        if (it == it_end)
            break;
        else
            it++;
         }
bug

Most helpful comment

I think that I will be able to deal with this issue in the beginning of the next week. If I fail to get this thing done, I'll let you know :wink:

All 4 comments

You tripped into something. The issue is that the all end iterators are being created with the default constructor, when they should mimic the behavior of "some next element that should not be dereferenced".

@frozar Can I count on you to have a look at this one then?

I think that I will be able to deal with this issue in the beginning of the next week. If I fail to get this thing done, I'll let you know :wink:

Ok, finally this issue is fixed in the branch octree_iterator_fix:
https://github.com/frozar/pcl/tree/octree_iterator_fix

I wait the end of the pull request #1983 before to propose a new one of this issue.

Was this page helpful?
0 / 5 - 0 ratings