rdiankov / openrave

Open Robotics Automation Virtual Environment: An environment for testing, developing, and deploying robotics motion planning algorithms.
http://www.openrave.org
Other
696 stars 342 forks source link

Compile error when trying to index a py::object with size_t key #1252

Closed undisputed-seraphim closed 1 year ago

undisputed-seraphim commented 1 year ago

When compiling natively with certain combinations of flags:

cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DODE_USE_MULTITHREAD=ON \
    -DOPT_IKFAST_FLOAT32=OFF \
    -DOPENRAVE_MSGPACK=OFF  \
    -DOPT_LOG4CXX=ON \
    -DBoost_NO_BOOST_CMAKE=OFF \
    -DUSE_PYBIND11_PYTHON_BINDINGS=ON \
    -DOPT_INSTALL_3DMODELDATA=OFF \
    -DOPT_MSGPACK=OFF \
    -DOPT_CURL=OFF \
    -DOPT_OCTAVE=OFF \
    -DOPT_COLLADA=OFF \
    -DOPT_MATLAB=OFF \
    -DOPT_STATIC=OFF \
    -DOPT_PYTHON=OFF  \
    -DCMAKE_CXX_FLAGS="-Wno-shadow"

I ran into a compilation error:

/home/user/Code/openrave/python/bindings/openravepy_global.cpp:355:75: error: invalid conversion from ‘size_t’ {aka ‘long unsigned int’} to ‘const char*’ [-fpermissive]
  355 |         vOrientedBox[iOrientedBox] = ExtractOrientedBox(pyOrientedBoxList[iOrientedBox]);
      |                                                                           ^~~~~~~~~~~~
      |                                                                           |
      |                                                                           size_t {aka long unsigned int}

The reason is because py::object::operator[] takes a string (const char*) instead of an integral value like size_t.

I imagine that what we really want is to cast the py::object into a py::list before trying to index it, so I applied a fix that does so accordingly.

I'm not sure why this error is not encountered in other builds. Perhaps it's due to very old versions of pybind11?


Edit by ciel: This is a new instances of https://github.com/rdiankov/openrave/pull/1125 .

cielavenir commented 1 year ago

@undisputed-seraphim what exact version of pybind11 did you use? (v2.9.2 / v2.9_ty / mujin_v2.9.2 / other)

cielavenir commented 1 year ago

if you use STOCK v2.9.2, what you need is INSTEAD:

-vOrientedBox[iOrientedBox] = ExtractOrientedBox(pyOrientedBoxList[iOrientedBox]);
+vOrientedBox[iOrientedBox] = ExtractOrientedBox(pyOrientedBoxList[py::to_object(iOrientedBox)]);

This is described in https://github.com/rdiankov/openrave/pull/1125 .

undisputed-seraphim commented 1 year ago

@undisputed-seraphim what exact version of pybind11 did you use? (v2.9.2 / v2.9_ty / mujin_v2.9.2 / other)

The version I am using is 2.9.2 stock.

cielavenir commented 1 year ago

Please try py::to_object(iOrientedBox) then

undisputed-seraphim commented 1 year ago

Pipeline #561845

cielavenir commented 1 year ago

@undisputed-seraphim Thank you! Are there any other places?

undisputed-seraphim commented 1 year ago

I didn't encounter any more compile error so I think that's all

cielavenir commented 1 year ago

thank you for checking!

rdiankov commented 1 year ago

got it, thanks