Skip to content

Commit

Permalink
Correctly error when inserting a duplicate attribute with mis-matchin…
Browse files Browse the repository at this point in the history
…g type
  • Loading branch information
Dan Bailey committed Nov 28, 2016
1 parent 98ac8e4 commit 990f093
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion openvdb/points/AttributeSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ AttributeSet::Descriptor::insert(const std::string& name, const NamePair& typeNa
size_t pos = INVALID_POS;
auto it = mNameMap.find(name);
if (it != mNameMap.end()) {
if (it->first != typeName.first) {
assert(it->second < mTypes.size());
if (mTypes[it->second] != typeName) {
OPENVDB_THROW(KeyError, "Cannot insert into a Descriptor with a duplicate name, but different type.")
}
pos = it->second;
Expand Down
6 changes: 6 additions & 0 deletions openvdb/unittest/TestAttributeSet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ TestAttributeSet::testAttributeSet()
Descriptor::Ptr descrB =
attrSetB.descriptor().duplicateAppend("test", AttributeS::attributeType());

// should throw if we attempt to add the same attribute name but a different type
CPPUNIT_ASSERT_THROW(descrB->insert("test", AttributeI::attributeType()), openvdb::KeyError);

// shouldn't throw if we attempt to add the same attribute name and type
CPPUNIT_ASSERT_NO_THROW(descrB->insert("test", AttributeS::attributeType()));

openvdb::TypedMetadata<AttributeS::ValueType> defaultValueTest(5);

// add a default value of the wrong type
Expand Down

0 comments on commit 990f093

Please sign in to comment.