Skip to content

Commit

Permalink
size check
Browse files Browse the repository at this point in the history
Signed-off-by: Dharini Dutia <dharini@openrobotics.org>
  • Loading branch information
quarkytale committed Jan 10, 2024
1 parent 404ffef commit d5ad0cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/rendering/MaterialParser/ConfigLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <utility>
#include <vector>

#include <gz/common/Console.hh>
#include <gz/common/Filesystem.hh>
#include "gz/sim/InstallationDirectories.hh"

Expand Down
10 changes: 10 additions & 0 deletions src/rendering/MaterialParser/ConfigLoader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <string>
#include <vector>

#include <gz/common/Console.hh>

namespace gz
{
namespace sim
Expand Down Expand Up @@ -120,6 +122,14 @@ public:
}
}

inline void getColorValues(std::vector<float> & colorValues)
{
getValuesInFloat(colorValues);
if (colorValues.size() < 3) {
gzerr << "Bad material file." << std::endl;

Check warning on line 129 in src/rendering/MaterialParser/ConfigLoader.hh

View check run for this annotation

Codecov / codecov/patch

src/rendering/MaterialParser/ConfigLoader.hh#L129

Added line #L129 was not covered by tests
}
}

inline const std::string & getValue(unsigned int index = 0)
{
assert(index < m_values.size());
Expand Down
8 changes: 4 additions & 4 deletions src/rendering/MaterialParser/MaterialParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::optional<MaterialParser::MaterialValues> MaterialParser::GetMaterialValues(
for (it = scripts.begin(); it != scripts.end(); ++it) {
std::string name = it->first;
if (name.find(material) != std::string::npos) {
if(!values) {
if (!values) {
values = MaterialValues();
}
ConfigNode * node = it->second;
Expand All @@ -63,23 +63,23 @@ std::optional<MaterialParser::MaterialValues> MaterialParser::GetMaterialValues(
ConfigNode * ambientNode = passNode->findChild("ambient");
if (ambientNode) {
std::vector<float> ambientValues;
ambientNode->getValuesInFloat(ambientValues);
ambientNode->getColorValues(ambientValues);
values->ambient.emplace(gz::math::Color(ambientValues[0],
ambientValues[1], ambientValues[2]));
}

ConfigNode * diffuseNode = passNode->findChild("diffuse");
if (diffuseNode) {
std::vector<float> diffuseValues;
diffuseNode->getValuesInFloat(diffuseValues);
diffuseNode->getColorValues(diffuseValues);
values->diffuse.emplace(gz::math::Color(diffuseValues[0],
diffuseValues[1], diffuseValues[2]));
}

ConfigNode * specularNode = passNode->findChild("specular");
if (specularNode) {
std::vector<float> specularValues;
specularNode->getValuesInFloat(specularValues);
specularNode->getColorValues(specularValues);
// Using first four values for specular as
// Gazebo doesn't support shininess
values->specular.emplace(gz::math::Color(specularValues[0],
Expand Down

0 comments on commit d5ad0cf

Please sign in to comment.