Skip to content

Commit 077e97c

Browse files
MichaelOrlovmorlov-apexai
authored andcommitted
Follow-up on "Fix for multibag replay stagnation (#2158)"
- Return player storage options by value in the 'get_storage_options()' to avoid returning dangling reference. Signed-off-by: Michael Orlov <michael.orlov@apex.ai>
1 parent 951d175 commit 077e97c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

rosbag2_transport/include/rosbag2_transport/player.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,10 @@ class Player : public rclcpp::Node
380380
size_t get_number_of_registered_on_play_msg_post_callbacks();
381381

382382
/// \brief Getter for the first of the currently stored storage options
383-
/// \return Reference to the first item in the StorageOptions vector
383+
/// \return Copy of the first item in the StorageOptions vector
384+
[[deprecated("Use rosabg2_transport::Player::get_all_storage_options() instead")]]
384385
ROSBAG2_TRANSPORT_PUBLIC
385-
const rosbag2_storage::StorageOptions & get_storage_options();
386+
rosbag2_storage::StorageOptions get_storage_options();
386387

387388
/// \brief Getter for the currently stored storage options
388389
/// \return Copy of the currently stored storage options

rosbag2_transport/src/rosbag2_transport/player.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class PlayerImpl
242242

243243
/// \brief Getter for the first of the currently stored storage options
244244
/// \return Copy of the first of the currently stored storage options
245-
const rosbag2_storage::StorageOptions & get_storage_options();
245+
rosbag2_storage::StorageOptions get_storage_options();
246246

247247
/// \brief Getter for the currently stored storage options
248248
/// \return Copy of the currently stored storage options
@@ -2179,10 +2179,10 @@ void PlayerImpl::publish_clock_update(const rclcpp::Time & time)
21792179
}
21802180
}
21812181

2182-
const rosbag2_storage::StorageOptions & PlayerImpl::get_storage_options()
2182+
rosbag2_storage::StorageOptions PlayerImpl::get_storage_options()
21832183
{
21842184
auto all_storage_options = get_all_storage_options();
2185-
if (all_storage_options.size() < 1) {
2185+
if (all_storage_options.empty()) {
21862186
throw std::runtime_error("Storage options not available.");
21872187
}
21882188
return all_storage_options[0];
@@ -2448,7 +2448,7 @@ size_t Player::get_number_of_registered_on_play_msg_post_callbacks()
24482448
return pimpl_->get_number_of_registered_on_play_msg_post_callbacks();
24492449
}
24502450

2451-
const rosbag2_storage::StorageOptions & Player::get_storage_options()
2451+
rosbag2_storage::StorageOptions Player::get_storage_options()
24522452
{
24532453
return pimpl_->get_storage_options();
24542454
}

0 commit comments

Comments
 (0)