Skip to content

Commit

Permalink
Stop asynchronous ROS updates with synchronous ones
Browse files Browse the repository at this point in the history
VisualizationManager uses [start|stop]Update() to pause ROS updates during dialog box interaction (ros-visualization#631).
However, asynchronous updates via threaded_queue_ were still performed, leading to a memory leak (ros-visualization#1621),
because messages were partially processed by the thread (i.e. kept in memory), but not finally processed
(and cleaned up) by the synchronous Display::update() call.
Pausing threaded processing too resolves that issue.
  • Loading branch information
rhaschke committed Jun 17, 2021
1 parent 3fa78da commit 9919269
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/rviz/visualization_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,25 +222,26 @@ VisualizationManager::VisualizationManager(RenderPanel* render_panel,

selection_manager_ = new SelectionManager(this);

update_timer_ = new QTimer;
connect(update_timer_, SIGNAL(timeout()), this, SLOT(onUpdate()));

private_->threaded_queue_threads_.create_thread(
boost::bind(&VisualizationManager::threadedQueueThreadFunc, this));

display_factory_ = new DisplayFactory();

ogre_render_queue_clearer_ = new OgreRenderQueueClearer();
Ogre::Root::getSingletonPtr()->addFrameListener(ogre_render_queue_clearer_);

update_timer_ = new QTimer;
connect(update_timer_, SIGNAL(timeout()), this, SLOT(onUpdate()));
}

VisualizationManager::~VisualizationManager()
{
delete update_timer_;

update_timer_->stop();
shutting_down_ = true;
private_->threaded_queue_threads_.join_all();

delete update_timer_;

if (selection_manager_)
{
selection_manager_->setSelection(M_Picked());
Expand Down Expand Up @@ -630,9 +631,13 @@ void VisualizationManager::handleChar(QKeyEvent* event, RenderPanel* panel)

void VisualizationManager::threadedQueueThreadFunc()
{
ros::WallDuration timeout(0.1);
while (!shutting_down_)
{
private_->threaded_queue_.callOne(ros::WallDuration(0.1));
if (update_timer_->isActive())
private_->threaded_queue_.callOne(timeout);
else
timeout.sleep();
}
}

Expand Down

0 comments on commit 9919269

Please sign in to comment.