Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseStencil::max() compiler error #1610

Closed
smauch opened this issue May 1, 2023 · 0 comments · Fixed by #1673
Closed

BaseStencil::max() compiler error #1610

smauch opened this issue May 1, 2023 · 0 comments · Fixed by #1673
Labels

Comments

@smauch
Copy link

smauch commented May 1, 2023

Environment

Operating System: (Ubuntu 20.04)
Version / Commit SHA: (OpenVDB 10.0.1)
Other: (GCC 9.4.0)

Describe the bug

The BaseStencil::max() function in Stencils.h causes a compiler error when used.

/usr/local/include/openvdb/math/Stencils.h:155:41: error: conversion from ‘__normal_iterator<const float*,[...]>’ to non-scalar type ‘__normal_iterator<float*,[...]>’ requested
  155 |         IterType iter = std::max_element(mValues.begin(), mValues.end());

To Reproduce

#include <iostream>
#include <openvdb/math/Stencils.h>
#include <openvdb/openvdb.h>

int main()
{
  openvdb::FloatGrid::Ptr grid = openvdb::FloatGrid::create();
  openvdb::math::BoxStencil<openvdb::FloatGrid> stencil(*grid);
  stencil.moveTo(openvdb::Coord(0, 0, 0));
  float max = stencil.max();
  return 0;
}

Reason

The reason for this issue is that, within the std::max_element() function call, mValues.begin() returns a const_iterator, as the member variable mValues is considered const due to BaseStencil::max() being a const member function.

Solution

The typedef of IterType should be typename BufferType::const_iterator instead of typename BufferType::iterator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant