Skip to content

Add static cast for buffer data + force C++-17#92

Draft
luca-della-vedova wants to merge 2 commits intomainfrom
luca/floorplan_rolling
Draft

Add static cast for buffer data + force C++-17#92
luca-della-vedova wants to merge 2 commits intomainfrom
luca/floorplan_rolling

Conversation

@luca-della-vedova
Copy link
Copy Markdown
Member

@luca-della-vedova luca-della-vedova commented Apr 23, 2026

Bug fix

Fixed bug

Fixes builds on rolling.

Fix applied

Rolling builds for rmf_visualization_floorplans have been failing with this kind of error (from buildfarm):

/tmp/binarydeb/ros-rolling-rmf-visualization-floorplans-2.5.1/src/FloorplanVisualizer.cpp:77:39: error: no matching function for call to ‘cv::Mat::Mat(const rmf_building_map_msgs::msg::AffineImage_<std::allocator<void> >::_data_type&)’
   77 |           cv::Mat(level.images[0].data), cv::IMREAD_GRAYSCALE);
      |                                       ^
In file included from /usr/include/opencv4/opencv2/core.hpp:58,
                 from /usr/include/opencv4/opencv2/core/core.hpp:48,
                 from /tmp/binarydeb/ros-rolling-rmf-visualization-floorplans-2.5.1/src/FloorplanVisualizer.cpp:21:
/usr/include/opencv4/opencv2/core/mat.hpp:1057:37: note: candidate: ‘template<class _Tp> cv::Mat::Mat(const cv::MatCommaInitializer_<_Tp>&)’
 1057 |     template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
      |                                     ^~~
/usr/include/opencv4/opencv2/core/mat.hpp:1057:37: note:   template argument deduction/substitution failed:
/tmp/binarydeb/ros-rolling-rmf-visualization-floorplans-2.5.1/src/FloorplanVisualizer.cpp:77:39: note:   ‘const rmf_building_map_msgs::msg::AffineImage_<std::allocator<void> >::_data_type’ {aka ‘const rosidl::Buffer<unsigned char, std::allocator<unsigned char> >’} is not derived from ‘const cv::MatCommaInitializer_<_Tp>’
   77 |           cv::Mat(level.images[0].data), cv::IMREAD_GRAYSCALE);

The issue seems to be due to the new Buffer introduced in rosidl, meant to be an abstraction for a CPU or GPU buffer.
It seems it can be implicitly converted do its inner std::vector (ref), so I just added a static_cast to the inner vector type. This should:

  • Convert the buffer.
  • Do nothing on older ROS versions where the data field is a std::vector in the first place.

Hence this should fix rolling builds without breaking compatibility with older ROS distros.

Furthermore, rmf_visualization_schedule builds are broken for a reason similar to rmf_websocket, with the difference that here it seems a transitive target is forcing the CXX version, so we need to override it.

Test it!

Build it under rolling (you will need to build rolling from source since it's not released yet), then build it under Jazzy.

GenAI Use

We follow OSRA's policy on GenAI tools

  • I used a GenAI tool in this PR.
  • I did not use GenAI

Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
Signed-off-by: Luca Della Vedova <lucadv@intrinsic.ai>
@luca-della-vedova luca-della-vedova changed the title Add static cast for buffer data Add static cast for buffer data + force C++-17 Apr 23, 2026
@luca-della-vedova luca-della-vedova marked this pull request as draft April 28, 2026 03:00
@luca-della-vedova
Copy link
Copy Markdown
Member Author

We should probably revert the hacky C++-17 change but it is pending a fix on rmf_websocket itself to have it C++-20 compatible. Marking as draft for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

2 participants