gazebosim / gz-rendering

C++ library designed to provide an abstraction for different rendering engines. It offers unified APIs for creating 3D graphics applications.
https://gazebosim.org
Apache License 2.0
56 stars 51 forks source link

DepthCamera compilation error on clang / macOS #29

Closed osrf-migration closed 5 years ago

osrf-migration commented 5 years ago

Original report (archived issue) by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


There is a compilation error for clang / macOS in OgreScene.cc related to the DepthCamera class since pull request #93. I haven't tested with clang on Ubuntu yet.

ogre/src/OgreScene.cc:376:34: error: no viable conversion from 'shared_ptr<ignition::rendering::v1::OgreDepthCamera>' to
      'shared_ptr<ignition::rendering::v1::OgreObject>'
  bool result = this->InitObject(camera, _id, _name);
                                 ^~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3703:23: note: candidate constructor not viable: no known conversion from
      'ignition::rendering::v1::OgreDepthCameraPtr' (aka 'std::__1::shared_ptr<ignition::rendering::v1::OgreDepthCamera>') to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument
    _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3717:5: note: candidate constructor not viable: no known conversion from
      'ignition::rendering::v1::OgreDepthCameraPtr' (aka 'std::__1::shared_ptr<ignition::rendering::v1::OgreDepthCamera>') to 'const
      std::__1::shared_ptr<ignition::rendering::v1::OgreObject> &' for 1st argument
    shared_ptr(const shared_ptr& __r) _NOEXCEPT;
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3725:5: note: candidate constructor not viable: no known conversion from
      'ignition::rendering::v1::OgreDepthCameraPtr' (aka 'std::__1::shared_ptr<ignition::rendering::v1::OgreDepthCamera>') to
      'std::__1::shared_ptr<ignition::rendering::v1::OgreObject> &&' for 1st argument
    shared_ptr(shared_ptr&& __r) _NOEXCEPT;
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3720:9: note: candidate template ignored: requirement
      'is_convertible<OgreDepthCamera *, element_type *>::value' was not satisfied [with _Yp = ignition::rendering::v1::OgreDepthCamera]
        shared_ptr(const shared_ptr<_Yp>& __r,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3726:52: note: candidate template ignored: requirement
      'is_convertible<OgreDepthCamera *, element_type *>::value' was not satisfied [with _Yp = ignition::rendering::v1::OgreDepthCamera]
    template<class _Yp> _LIBCPP_INLINE_VISIBILITY  shared_ptr(shared_ptr<_Yp>&& __r,
                                                   ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3745:9: note: candidate template ignored: could not match 'unique_ptr'
      against 'shared_ptr'
        shared_ptr(unique_ptr<_Yp, _Dp>&&,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:3754:9: note: candidate template ignored: could not match 'unique_ptr'
      against 'shared_ptr'
        shared_ptr(unique_ptr<_Yp, _Dp>&&,
        ^
/Users/jenkins/Desktop/ign-rendering/ogre/include/ignition/rendering/ogre/OgreScene.hh:142:56: note: passing argument to parameter '_object' here
      protected: virtual bool InitObject(OgreObjectPtr _object,
                                                       ^
1 error generated.

The clearest way to see the error is by adding the following static_assert:

diff -r 2cae5cb00bff44f0a97c38332713ea37fa391c52 ogre/src/OgreDepthCamera.cc
--- a/ogre/src/OgreDepthCamera.cc       Thu Oct 11 11:47:22 2018 -0700
+++ b/ogre/src/OgreDepthCamera.cc       Thu Oct 11 15:59:53 2018 -0700
@@ -15,6 +15,7 @@
  *
 */

+#include <type_traits>
 #include "ignition/rendering/ogre/OgreDepthCamera.hh"
 #include <ignition/math/Helpers.hh>
 #if (_WIN32)
@@ -30,6 +31,7 @@
 OgreDepthCamera::OgreDepthCamera()
   : dataPtr(new OgreDepthCameraPrivate())
 {
+  static_assert(std::is_convertible<OgreDepthCamera*, OgreObject*>::value);
 }

 //////////////////////////////////////////////////

This passes on Ubuntu with gcc, but fails on macOS with clang:

ogre/src/OgreDepthCamera.cc:34:3:
 error: static_assert failed due to requirement 'std::is_convertible<OgreDepthCamera *, OgreObject *>::value'
  static_assert(std::is_convertible<OgreDepthCamera*, OgreObject*>::value);
  ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [ogre/src/CMakeFiles/ignition-rendering1-ogre.dir/OgreDepthCamera.cc.o] Error 1
make[1]: *** [ogre/src/CMakeFiles/ignition-rendering1-ogre.dir/all] Error 2
make: *** [all] Error 2

cc @JChoclin

osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


One thing to check is if this failure occurs with clang on Ubuntu.

osrf-migration commented 5 years ago

Original comment by Ian Chen (Bitbucket: Ian Chen, GitHub: iche033).


osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


I just confirmed that the build fails with clang on ubuntu, but it also gave an extra error message with a clue about how to fix it:

error: cannot cast
      'ignition::rendering::v1::OgreDepthCamera' to its protected base class 'const
      std::enable_shared_from_this<ignition::rendering::v1::BaseObject>'
          if (auto __base = __enable_shared_from_this_base(_M_refcount, __p))
                                                                        ^
...
include/ignition/rendering/base/BaseDepthCamera.hh:43:7: note: constrained by protected inheritance
      here
      protected virtual BaseCamera<T>,
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I'm testing inheriting with public instead of protected in d320c7365e0e6f474b6ddfd2a109552f7b95dca6

osrf-migration commented 5 years ago

Original comment by Steve Peters (Bitbucket: Steven Peters, GitHub: scpeters).


osrf-migration commented 5 years ago

Original comment by Ian Chen (Bitbucket: Ian Chen, GitHub: iche033).