Browse Source

Trade: print layer index in MaterialData duplicate attribute assert.

With really huge materials it's kinda useless to not know which layer
the error happened in -- and usually it's exactly because the layer
indices were specified wrong.
pull/539/head
Vladimír Vondruš 4 years ago
parent
commit
b65a147f30
  1. 4
      src/Magnum/Trade/MaterialData.cpp
  2. 11
      src/Magnum/Trade/Test/MaterialDataTest.cpp

4
src/Magnum/Trade/MaterialData.cpp

@ -233,7 +233,7 @@ MaterialData::MaterialData(const MaterialTypes types, Containers::Array<Material
if(end - begin > 1) for(std::size_t j = begin + 1; j != end; ++j) {
if(_data[j - 1].name() < _data[j].name()) continue;
std::sort(_data + begin, _data + end, [](const MaterialAttributeData& a, const MaterialAttributeData& b) {
std::sort(_data + begin, _data + end, [i](const MaterialAttributeData& a, const MaterialAttributeData& b) {
/* Need to check here (instead of in the outer for loop) as we
exit the loop right after the sort and thus duplicates that
occur after the first non-sorted pair wouldn't get detected.
@ -244,7 +244,7 @@ MaterialData::MaterialData(const MaterialTypes types, Containers::Array<Material
which is undesirable). Apparently libc++ is responsible for
such atrocities. */
CORRADE_ASSERT(&a == &b || a.name() != b.name(),
"Trade::MaterialData: duplicate attribute" << a.name(), false);
"Trade::MaterialData: duplicate attribute" << a.name() << "in layer" << i, false);
return a.name() < b.name();
});
break;

11
src/Magnum/Trade/Test/MaterialDataTest.cpp

@ -978,6 +978,11 @@ void MaterialDataTest::constructDuplicateAttribute() {
#endif
Containers::Array<MaterialAttributeData> attributes{InPlaceInit, {
/* This attribute is in the first layer, so it should not be reported
as duplicated */
{MaterialAttribute::DoubleSided, true},
/* Second layer is empty, this is the third layer (index 2) */
{MaterialAttribute::DoubleSided, true},
{MaterialAttribute::DiffuseTextureCoordinates, 5u},
{"highlightColor", 0x335566ff_rgbaf},
@ -987,16 +992,16 @@ void MaterialDataTest::constructDuplicateAttribute() {
/* Testing that it asserts in all input permutations */
for(std::size_t i = 0; i != testCaseRepeatId(); ++i)
std::next_permutation(attributes.begin(), attributes.end(), [](const MaterialAttributeData& a, const MaterialAttributeData& b) {
std::next_permutation(attributes.begin() + 1, attributes.end(), [](const MaterialAttributeData& a, const MaterialAttributeData& b) {
return a.name() < b.name();
});
std::ostringstream out;
Error redirectError{&out};
MaterialData data{{}, std::move(attributes)};
MaterialData data{{}, std::move(attributes), Containers::array<UnsignedInt>({1, 1, 6})};
/* Because with graceful asserts it doesn't exit on error, the assertion
might get printed multiple times */
CORRADE_COMPARE(Utility::String::partition(out.str(), '\n')[0], "Trade::MaterialData: duplicate attribute DiffuseTextureCoordinates");
CORRADE_COMPARE(Utility::String::partition(out.str(), '\n')[0], "Trade::MaterialData: duplicate attribute DiffuseTextureCoordinates in layer 2");
}
void MaterialDataTest::constructFromImmutableSortedArray() {

Loading…
Cancel
Save