Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault when camera dispay closed. Closes #1372. #1393

Closed

Conversation

hexonxons
Copy link

Description

Actually segfault happens in CBQueueCallback::call method while calling filter_->signalMessage(event_):

virtual CallResult call()
{
  if (success_)
  {
    filter_->signalMessage(event_);
  }
  else
  {
    filter_->signalFailure(event_, reason_);
  }

  return Success;
}

CBQueueCallback object is constructed in MessageFilter::messageReady method:

ros::CallbackInterfacePtr cb(new CBQueueCallback(this, evt, true, filter_failure_reasons::Unknown));
callback_queue_->addCallback(cb, (uint64_t)this);

and it holds MessageFilter pointer as argument:

 CBQueueCallback(MessageFilter* filter, const MEvent& event, bool success, FilterFailureReason reason)
    : event_(event)
    , filter_(filter)
    , reason_(reason)
    , success_(success)
    {}

At call time filter_ object is already destroyed in

void ImageDisplayBase::unsubscribe()
{
tf_filter_.reset();
sub_.reset(new image_transport::SubscriberFilter());
}
and this leads to segfault.

CBQueueCallback object is called from callback_queue_:

ros::CallbackInterfacePtr cb(new CBQueueCallback(this, evt, true, filter_failure_reasons::Unknown));
callback_queue_->addCallback(cb, (uint64_t)this);

which actually the same as update_nh_.getCallbackQueue():

template<class F>
  MessageFilter(F& f, tf2::BufferCore& bc, const std::string& target_frame, uint32_t queue_size, const ros::NodeHandle& nh)
  : bc_(bc)
  , queue_size_(queue_size)
  , callback_queue_(nh.getCallbackQueue())
  {
    init();

    setTargetFrame(target_frame);

    connectInput(f);
  }

This all looks like a thread sync problem, but I wasn't able to track it.
I am unsure if it is bug in TF2 message filter, so I suggest to use less invasive method and fix this bug in RViz code by removing callback by id before message_filter reset.

@rhaschke
Copy link
Contributor

Thanks a lot for your detailed analysis. Based on your work, I filed a PR in ros/geometry2#402. Closing here, as this should be fixed upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants