From c5e70c40eb8f0c29af1511dfcfd01211df7f1fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 17 Mar 2020 21:37:01 +0100 Subject: [PATCH] MeshTools: ensure proper assert is printed in compressIndices(). --- src/Magnum/MeshTools/CompressIndices.cpp | 5 ++++- src/Magnum/MeshTools/Test/CompressIndicesTest.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Magnum/MeshTools/CompressIndices.cpp b/src/Magnum/MeshTools/CompressIndices.cpp index b37342a58..96460fb50 100644 --- a/src/Magnum/MeshTools/CompressIndices.cpp +++ b/src/Magnum/MeshTools/CompressIndices.cpp @@ -165,9 +165,12 @@ Trade::MeshData compressIndices(Trade::MeshData&& data, MeshIndexType atLeast) { } Trade::MeshData compressIndices(const Trade::MeshData& data, MeshIndexType atLeast) { + CORRADE_ASSERT(data.isIndexed(), "MeshTools::compressIndices(): mesh data not indexed", (Trade::MeshData{MeshPrimitive::Triangles, 0})); + return compressIndices(Trade::MeshData{data.primitive(), {}, data.indexData(), Trade::MeshIndexData{data.indices()}, - {}, data.vertexData(), Trade::meshAttributeDataNonOwningArray(data.attributeData())}, atLeast); + {}, data.vertexData(), Trade::meshAttributeDataNonOwningArray(data.attributeData()), + data.vertexCount()}, atLeast); } #ifdef MAGNUM_BUILD_DEPRECATED diff --git a/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp b/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp index 476475f89..655417594 100644 --- a/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp +++ b/src/Magnum/MeshTools/Test/CompressIndicesTest.cpp @@ -316,10 +316,14 @@ void CompressIndicesTest::compressMeshDataMove() { } void CompressIndicesTest::compressMeshDataNonIndexed() { + /* Test both r-value and l-value overload */ std::ostringstream out; Error redirectError{&out}; + Trade::MeshData mesh{MeshPrimitive::TriangleFan, 5}; + MeshTools::compressIndices(mesh); MeshTools::compressIndices(Trade::MeshData{MeshPrimitive::TriangleFan, 5}); CORRADE_COMPARE(out.str(), + "MeshTools::compressIndices(): mesh data not indexed\n" "MeshTools::compressIndices(): mesh data not indexed\n"); }