Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

why does RemoveSensor() on sonar sensor during Load() cause a crash?

Hi,

I'm writing a ModelPlugin to run alongside a model specified in SDF (Gazebo 7.0). The SDF includes a <sensor> snippet for a sonar sensor and a camera sensor, and I want to delete them in the plugin (optionally) to eliminate their CPU cost. Calling SetActive(false) on them disables them, but they still use CPU.

In ModelPlugin::Load(), I can call SensorManager::RemoveSensor() on the camera sensor, and everything works as expected - the camera goes away, and the CPU usage is reduced. I want to do the same to the sonar sensor, but if I call SensorManager::RemoveSensor() on that one, I get a crash shortly afterwards that says:

gzserver: /usr/include/boost/smart_ptr/shared_ptr.hpp:648: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = gazebo::physics::SurfaceParams; typename boost::detail::sp_member_access<T>::type = gazebo::physics::SurfaceParams*]: Assertion 'px != 0' failed.

I am guessing this is happening because before the Load() call on my plugin, the sensor has registered itself with the physics engine in some way - the camera presumably does not need to do this. I've reviewed the source code for SonarSensor and see that there is a connect/disconnect function, but I can't see where I could recover the token in order to call disconnect() on it, even if that isn't barking up the wrong tree.

So - can anyone please tell me either why this crashes, or - more directly - what do I have to do to shut down the SonarSensor gracefully and allow me to RemoveSensor() it?

Thanks, ben