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
How did you measure the CPU usage when they are disabled: SetActive(false)? The SetActive(false) function should eliminate most or all of a sensor's processing.
Just monitoring externally using top/atop. Tried it just this minute - CPU @ 70% with nine inactive sonars; @ 35% when they are not present in the SDF. Sonar is implemented using contact detection, right? So perhaps this is still running in the background, which would explain the CPU use and also why I can't safely Remove() them... guess guess?
21 cameras gives me 130% CPU enabled, 98% CPU SetActive(false), 72% CPU RemoveSensor()'d. Similar pattern, except that I /can/ safely do RemoveSensor(), that works just fine.
Is it possible to post or link to your code and SDF file(s)?
Here's a link to a minimal example: run make in this folder to generate the error [ https://we.tl/t-G2YMhZx52k ] (sorry, comments are wrong; lines 150/153 *undefining)
Posted new link, old one will expire soon [ https://we.tl/t-bJaqf24w5f ]