Commit c0bb9d73 authored by Haocheng LIU's avatar Haocheng LIU

Query an entity's color status before fetching its color

In C++ if a key is not in the map, calling [] operator on it will create
a dummy entry. This will prevent other code to query the correct status
of the entity's color. By adding the right check code, an empty color property
will no longer be to the resource.
parent 82481608
......@@ -359,7 +359,7 @@ void EntityRef::setVisible(bool vis)
*/
FloatList EntityRef::color() const
{
FloatList result = this->floatProperty("color");
FloatList result = !this->hasColor() ? FloatList{} : this->floatProperty("color");
int ncomp = static_cast<int>(result.size());
if (ncomp < 4)
{
......
......@@ -1247,8 +1247,9 @@ bool Resource::hasFloatProperty(const UUID& entity, const std::string& propName)
return false;
}
FloatData::const_iterator sit = uit->second.find(propName);
// FIXME: Should we return true even when the array (*sit) is empty?
return sit == uit->second.end() ? false : true;
// when the array (*sit) is empty, we return true due to the fact that defing a dummy
// property should be considered ill formed
return sit == uit->second.end() ? false : !sit->second.empty();
}
bool Resource::removeFloatProperty(const UUID& entity, const std::string& propName)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment