From 31d7353ba6b211334b3a2aaf7d971dfda8b983be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 18 Dec 2022 20:57:02 +0100 Subject: [PATCH] Trade: use the fancy StridedArrayView slicing in MeshDataTest. Stone age APIs used here again, I can't fathom how I could live without member slicing for so long. This also fixes an OOB access which trips up the new ArrayView assertions -- accessing element 0 in the constructor isn't a good thing to do if there's no data at all. --- src/Magnum/Trade/Test/MeshDataTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Magnum/Trade/Test/MeshDataTest.cpp b/src/Magnum/Trade/Test/MeshDataTest.cpp index 998ec7efb..5c9065895 100644 --- a/src/Magnum/Trade/Test/MeshDataTest.cpp +++ b/src/Magnum/Trade/Test/MeshDataTest.cpp @@ -1237,7 +1237,7 @@ void MeshDataTest::construct() { /* Enough vertex data to fit also the case with large explicit vertex count (but fill just the first 3, as those are only tested) */ Containers::Array vertexData{17*sizeof(Vertex)}; - auto vertexView = Containers::arrayCast(vertexData).prefix(3); + auto vertexView = stridedArrayView(Containers::arrayCast(vertexData)).prefix(3); vertexView[0].position = {0.1f, 0.2f, 0.3f}; vertexView[1].position = {0.4f, 0.5f, 0.6f}; vertexView[2].position = {0.7f, 0.8f, 0.9f}; @@ -1260,16 +1260,16 @@ void MeshDataTest::construct() { int importerState; MeshIndexData indices{indexView}; MeshAttributeData positions{MeshAttribute::Position, - Containers::StridedArrayView1D{vertexData, &vertexView[0].position, vertexView.size(), sizeof(Vertex)}}; + vertexView.slice(&Vertex::position)}; /* Offset-only */ MeshAttributeData normals{MeshAttribute::Normal, VertexFormat::Vector3, offsetof(Vertex, normal), UnsignedInt(vertexView.size()), sizeof(Vertex)}; MeshAttributeData textureCoordinates{MeshAttribute::TextureCoordinates, - Containers::StridedArrayView1D{vertexData, &vertexView[0].textureCoordinate, vertexView.size(), sizeof(Vertex)}}; + vertexView.slice(&Vertex::textureCoordinate)}; /* Custom & array */ MeshAttributeData ids{meshAttributeCustom(13), - Containers::StridedArrayView2D{vertexData, &vertexView[0].id[0], {vertexView.size(), 2}, {sizeof(Vertex), sizeof(Short)}}}; + Containers::arrayCast<2, Short>(vertexView.slice(&Vertex::id))}; MeshData data{MeshPrimitive::Triangles, std::move(indexData), indices, /* Texture coordinates deliberately twice (though aliased) */