From b65a147f309392cda0297988749d17c0cba5822e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 7 Feb 2022 19:42:34 +0100 Subject: [PATCH] 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. --- src/Magnum/Trade/MaterialData.cpp | 4 ++-- src/Magnum/Trade/Test/MaterialDataTest.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Magnum/Trade/MaterialData.cpp b/src/Magnum/Trade/MaterialData.cpp index b939dff43..604d5cbe9 100644 --- a/src/Magnum/Trade/MaterialData.cpp +++ b/src/Magnum/Trade/MaterialData.cpp @@ -233,7 +233,7 @@ MaterialData::MaterialData(const MaterialTypes types, Containers::Array 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 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({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() {