Program crashes on reader.take() operation

2 posts / 0 new
Last post
Offline
Last seen: 1 year 6 months ago
Joined: 08/09/2017
Posts: 2
Program crashes on reader.take() operation

My program crashes on the first take() operation. The program is a plugin(.so) to another executable so 

waitset.dispatch() is called from a run() function called periodically from the parent.

void foo::run()
{
   mWaitSet.dispatch(dds::core::Duration(0,10));
}

The participant is created in the constructor:

foo::foo(const std::string &name) :

mProvider(QOS_LOCATION),
mParticipant(10,mProvider.participant_qos("ParticipantProfile"))

 

The reader callback is constructed here:

template <class T>
dds::sub::cond::ReadCondition foo::make_read_condition(dds::sub::DataReader<T>& reader)
{
return dds::sub::cond::ReadCondition(
reader,
dds::sub::status::DataState::any(),
[&reader,this]()
{
// Take all samples
dds::sub::LoanedSamples<T> samples = reader.take();      /// CRASH HERE
for (auto sample : samples)
{
       if (sample.info().valid())
       {
              this->processMsg(sample.data());


       }
}
} // The LoanedSamples destructor returns the loan
);
}

The topic and reader are created here:

dds::sub::DataReader<DDSmsg> msgReader(Subscriber(mParticipant), Topic<DDSmsg>(mParticipant, "DDSmsg"));
mWaitSet += make_read_condition(msgReader);

I put a print in TDataReader.hpp and the pointer looks good...

LoanedSamples<T> read()
{

  printf("this = %p\n",this);
return this->delegate()->take();
}

I have used this same code in several other applications with no problem

 

Offline
Last seen: 1 year 6 months ago
Joined: 08/09/2017
Posts: 2

[SOLVED] Fixed this problem by making the data reader a class variable, making make_read_condition() a class method and calling make_read_condition from the constructor.