KITmedical / kacanopen

Easy-to-use CanOpen stack and CanOpen-to-ROS bridge.
Other
93 stars 57 forks source link

Memory access violation when remapping PDOs in master side #13

Open xdaco opened 6 years ago

xdaco commented 6 years ago

Hi, I have been using this library to control CiA401 devices and I found a memory access violation issue if we try to remap pdo after a deleting old device and creating a new one. The issue was related to the residual add_pdo_received_callback entry. The workaround is to remove the residual add_pdo_received_callback while destroying a device.

Device::~Device() { for (auto& cob_id : cobids) m_core.pdo.remove_pdo_received_callback(cob_id); }

void PDO::remove_pdo_received_callback(uint16_t cob_id) { std::lock_guard scoped_lock(m_receive_callbacks_mutex); for (auto i = m_receive_callbacks.begin(); i != m_receive_callbacks.end(); i++) if ((*i).cob_id == cob_id) { m_receive_callbacks.erase(i); break; } }

I am now trying to write a master side example which handles multiple slave device on the same bus. Any suggestion will really be appreciated.

thk1 commented 6 years ago

Hi. Thanks for the report. Could you please create a pull request for this change?