Use shared pointer when binding callback for serial read (#38)

* Resolves an issue with ROS Melodic on 18.04.
This commit is contained in:
Yutaka Kondo 2019-08-20 02:32:00 +09:00 committed by Jacob Perron
parent 070550e655
commit 2442ba209c
2 changed files with 4 additions and 3 deletions

View file

@ -72,7 +72,7 @@ namespace create {
// Start continuously reading one byte at a time
boost::asio::async_read(port,
boost::asio::buffer(&byteRead, 1),
boost::bind(&Serial::onData, this, _1, _2));
boost::bind(&Serial::onData, shared_from_this(), _1, _2));
ioThread = boost::thread(boost::bind(&boost::asio::io_service::run, &io));
@ -145,7 +145,7 @@ namespace create {
// Read the next byte
boost::asio::async_read(port,
boost::asio::buffer(&byteRead, 1),
boost::bind(&Serial::onData, this, _1, _2));
boost::bind(&Serial::onData, shared_from_this(), _1, _2));
}
bool Serial::send(const uint8_t* bytes, unsigned int numBytes) {