From debcbcb8d5325c74d024f6279215d114ea34a896 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sun, 3 Apr 2016 10:57:31 +0200 Subject: [PATCH] don't use a static ClassLoader instance - crashes on exit: https://github.com/ros/class_loader/issues/33 - on-demand-unloading works with https://github.com/ros/class_loader/pull/34 --- urdf/src/sensor.cpp | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/urdf/src/sensor.cpp b/urdf/src/sensor.cpp index a7819b71..45b6f461 100644 --- a/urdf/src/sensor.cpp +++ b/urdf/src/sensor.cpp @@ -89,34 +89,28 @@ SensorMap parseSensors(const std::string &xml_string, const SensorParserMap &par SensorParserMap getSensorParsers(const std::vector &allowed) { - static boost::mutex PARSER_PLUGIN_LOCK; - static boost::shared_ptr > PARSER_PLUGIN_LOADER; - boost::mutex::scoped_lock _(PARSER_PLUGIN_LOCK); - + pluginlib::ClassLoader loader("urdf", "urdf::SensorParser"); SensorParserMap parserMap; try { - if (!PARSER_PLUGIN_LOADER) - PARSER_PLUGIN_LOADER.reset(new pluginlib::ClassLoader("urdf", "urdf::SensorParser")); - - const std::vector &classes = PARSER_PLUGIN_LOADER->getDeclaredClasses(); - for (std::size_t i = 0 ; i < classes.size() ; ++i) - { - // skip this class if not listed in allowed - if (!allowed.empty() && std::find(allowed.begin(), allowed.end(), classes[i]) == allowed.end()) - continue; - - urdf::SensorParserSharedPtr parser; - try { - parser = PARSER_PLUGIN_LOADER->createInstance(classes[i]); - } catch(const pluginlib::PluginlibException& ex) { - ROS_ERROR_STREAM("Failed to create sensor parser: " << classes[i] << "\n" << ex.what()); - } - parserMap.insert(std::make_pair(classes[i], parser)); - ROS_DEBUG_STREAM("added sensor parser: " << classes[i]); + const std::vector &classes = loader.getDeclaredClasses(); + for (std::size_t i = 0 ; i < classes.size() ; ++i) + { + // skip this class if not listed in allowed + if (!allowed.empty() && std::find(allowed.begin(), allowed.end(), classes[i]) == allowed.end()) + continue; + + urdf::SensorParserSharedPtr parser; + try { + parser = loader.createInstance(classes[i]); + } catch(const pluginlib::PluginlibException& ex) { + ROS_ERROR_STREAM("Failed to create sensor parser: " << classes[i] << "\n" << ex.what()); } - if (parserMap.empty()) - ROS_WARN_STREAM("No sensor parsers found"); + parserMap.insert(std::make_pair(classes[i], parser)); + ROS_DEBUG_STREAM("added sensor parser: " << classes[i]); + } + if (parserMap.empty()) + ROS_WARN_STREAM("No sensor parsers found"); } catch(const pluginlib::PluginlibException& ex) {