Browse Source

Trade: improve MeshData type mismatch assertions.

We *do* know what type the user requested, so why not print it as well.
And for the array access the message was especially lazy.
pull/537/head
Vladimír Vondruš 5 years ago
parent
commit
26a0bf94ff
  1. 12
      src/Magnum/Trade/MeshData.h
  2. 28
      src/Magnum/Trade/Test/MeshDataTest.cpp

12
src/Magnum/Trade/MeshData.h

@ -2121,7 +2121,7 @@ template<class T> Containers::ArrayView<const T> MeshData::indices() const {
if(!data.stride()[1]) return {};
#endif
CORRADE_ASSERT(Implementation::meshIndexTypeFor<T>() == _indexType,
"Trade::MeshData::indices(): improper type requested for" << _indexType, nullptr);
"Trade::MeshData::indices(): indices are" << _indexType << "but requested" << Implementation::meshIndexTypeFor<T>(), nullptr);
return Containers::arrayCast<1, const T>(data).asContiguous();
}
@ -2133,7 +2133,7 @@ template<class T> Containers::ArrayView<T> MeshData::mutableIndices() {
if(!data.stride()[1]) return {};
#endif
CORRADE_ASSERT(Implementation::meshIndexTypeFor<T>() == _indexType,
"Trade::MeshData::mutableIndices(): improper type requested for" << _indexType, nullptr);
"Trade::MeshData::mutableIndices(): indices are" << _indexType << "but requested" << Implementation::meshIndexTypeFor<T>(), nullptr);
return Containers::arrayCast<1, T>(data).asContiguous();
}
@ -2142,9 +2142,11 @@ template<class T> bool MeshData::checkVertexFormatCompatibility(const MeshAttrib
CORRADE_ASSERT(!isVertexFormatImplementationSpecific(attribute._format),
prefix << "can't cast data from an implementation-specific vertex format" << reinterpret_cast<void*>(vertexFormatUnwrap(attribute._format)), false);
CORRADE_ASSERT(Implementation::isVertexFormatCompatible<typename std::remove_extent<T>::type>(attribute._format),
prefix << "improper type requested for" << attribute._name << "of format" << attribute._format, false);
CORRADE_ASSERT(std::is_array<T>::value == !!attribute._arraySize,
prefix << "use T[] to access an array attribute", false);
prefix << attribute._name << "is" << attribute._format << "but requested a type equivalent to" << Implementation::vertexFormatFor<typename std::remove_extent<T>::type>(), false);
if(attribute._arraySize) CORRADE_ASSERT(std::is_array<T>::value,
prefix << attribute._name << "is an array attribute, use T[] to access it", false);
else CORRADE_ASSERT(!std::is_array<T>::value,
prefix << attribute._name << "is not an array attribute, can't use T[] to access it", false);
return true;
}
#endif

28
src/Magnum/Trade/Test/MeshDataTest.cpp

@ -2750,14 +2750,14 @@ void MeshDataTest::arrayAttributeWrongAccess() {
data.mutableAttribute<Vector2[]>(MeshAttribute::Position);
data.mutableAttribute<Vector2>(meshAttributeCustom(35));
CORRADE_COMPARE(out.str(),
"Trade::MeshData::attribute(): use T[] to access an array attribute\n"
"Trade::MeshData::attribute(): use T[] to access an array attribute\n"
"Trade::MeshData::mutableAttribute(): use T[] to access an array attribute\n"
"Trade::MeshData::mutableAttribute(): use T[] to access an array attribute\n"
"Trade::MeshData::attribute(): use T[] to access an array attribute\n"
"Trade::MeshData::attribute(): use T[] to access an array attribute\n"
"Trade::MeshData::mutableAttribute(): use T[] to access an array attribute\n"
"Trade::MeshData::mutableAttribute(): use T[] to access an array attribute\n");
"Trade::MeshData::attribute(): Trade::MeshAttribute::Position is not an array attribute, can't use T[] to access it\n"
"Trade::MeshData::attribute(): Trade::MeshAttribute::Custom(35) is an array attribute, use T[] to access it\n"
"Trade::MeshData::mutableAttribute(): Trade::MeshAttribute::Position is not an array attribute, can't use T[] to access it\n"
"Trade::MeshData::mutableAttribute(): Trade::MeshAttribute::Custom(35) is an array attribute, use T[] to access it\n"
"Trade::MeshData::attribute(): Trade::MeshAttribute::Position is not an array attribute, can't use T[] to access it\n"
"Trade::MeshData::attribute(): Trade::MeshAttribute::Custom(35) is an array attribute, use T[] to access it\n"
"Trade::MeshData::mutableAttribute(): Trade::MeshAttribute::Position is not an array attribute, can't use T[] to access it\n"
"Trade::MeshData::mutableAttribute(): Trade::MeshAttribute::Custom(35) is an array attribute, use T[] to access it\n");
}
void MeshDataTest::mutableAccessNotAllowed() {
@ -2841,8 +2841,8 @@ void MeshDataTest::indicesWrongType() {
data.indices<UnsignedByte>();
data.mutableIndices<UnsignedByte>();
CORRADE_COMPARE(out.str(),
"Trade::MeshData::indices(): improper type requested for MeshIndexType::UnsignedShort\n"
"Trade::MeshData::mutableIndices(): improper type requested for MeshIndexType::UnsignedShort\n");
"Trade::MeshData::indices(): indices are MeshIndexType::UnsignedShort but requested MeshIndexType::UnsignedByte\n"
"Trade::MeshData::mutableIndices(): indices are MeshIndexType::UnsignedShort but requested MeshIndexType::UnsignedByte\n");
}
void MeshDataTest::attributeNotFound() {
@ -2964,10 +2964,10 @@ void MeshDataTest::attributeWrongType() {
data.mutableAttribute<Vector4>(MeshAttribute::Position);
data.mutableAttribute<Vector4[]>(MeshAttribute::Position);
CORRADE_COMPARE(out.str(),
"Trade::MeshData::attribute(): improper type requested for Trade::MeshAttribute::Position of format VertexFormat::Vector3\n"
"Trade::MeshData::attribute(): improper type requested for Trade::MeshAttribute::Position of format VertexFormat::Vector3\n"
"Trade::MeshData::mutableAttribute(): improper type requested for Trade::MeshAttribute::Position of format VertexFormat::Vector3\n"
"Trade::MeshData::mutableAttribute(): improper type requested for Trade::MeshAttribute::Position of format VertexFormat::Vector3\n");
"Trade::MeshData::attribute(): Trade::MeshAttribute::Position is VertexFormat::Vector3 but requested a type equivalent to VertexFormat::Vector4\n"
"Trade::MeshData::attribute(): Trade::MeshAttribute::Position is VertexFormat::Vector3 but requested a type equivalent to VertexFormat::Vector4\n"
"Trade::MeshData::mutableAttribute(): Trade::MeshAttribute::Position is VertexFormat::Vector3 but requested a type equivalent to VertexFormat::Vector4\n"
"Trade::MeshData::mutableAttribute(): Trade::MeshAttribute::Position is VertexFormat::Vector3 but requested a type equivalent to VertexFormat::Vector4\n");
}
void MeshDataTest::releaseIndexData() {

Loading…
Cancel
Save