From 5c06eecde885e1497fc7904b67b9b6c912049527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 31 Aug 2021 15:00:46 +0200 Subject: [PATCH] Trade: actually, do it like this. --- src/Magnum/Trade/MeshData.cpp | 41 ++++++++++++++++------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/Magnum/Trade/MeshData.cpp b/src/Magnum/Trade/MeshData.cpp index 4672f10a5..bc1f62a1d 100644 --- a/src/Magnum/Trade/MeshData.cpp +++ b/src/Magnum/Trade/MeshData.cpp @@ -133,28 +133,25 @@ MeshData::MeshData(const MeshPrimitive primitive, Containers::Array&& inde "Trade::MeshData: attribute" << i << "has" << attribute._vertexCount << "vertices but" << expectedAttributeVertexCount << "expected", ); /* Check that the view fits into the provided vertex data array. For implementation-specific formats we don't know the size so use 0 to - check at least partially. */ - const UnsignedInt typeSize = - isVertexFormatImplementationSpecific(attribute._format) ? 0 : - (vertexFormatSize(attribute._format)* - (attribute._arraySize ? attribute._arraySize : 1)); - if(attribute._isOffsetOnly) { - const std::size_t size = attribute._data.offset + (_vertexCount - 1)*attribute._stride + typeSize; - /* For meshes with zero vertices we don't check the pointer, since - accessing the memory is invalid anyway and enforcing this would - lead to unnecessary friction with interleaved attributes of - empty meshes. */ - CORRADE_ASSERT(!_vertexCount || size <= _vertexData.size(), - "Trade::MeshData: offset-only attribute" << i << "spans" << size << "bytes but passed vertexData array has only" << _vertexData.size(), ); - } else { - const void* const begin = static_cast(attribute._data.pointer); - const void* const end = static_cast(attribute._data.pointer) + (_vertexCount - 1)*attribute._stride + typeSize; - /* For meshes with zero vertices we don't check the pointer, since - accessing the memory is invalid anyway and enforcing this would - lead to unnecessary friction with interleaved attributes of - empty meshes. */ - CORRADE_ASSERT(!_vertexCount || (begin >= _vertexData.begin() && end <= _vertexData.end()), - "Trade::MeshData: attribute" << i << "[" << Debug::nospace << begin << Debug::nospace << ":" << Debug::nospace << end << Debug::nospace << "] is not contained in passed vertexData array [" << Debug::nospace << static_cast(_vertexData.begin()) << Debug::nospace << ":" << Debug::nospace << static_cast(_vertexData.end()) << Debug::nospace << "]", ); + check at least partially. If the mesh has zero vertices, we don't + check anything -- accessing the memory would be invalid anyway and + enforcing this would lead to unnecessary friction with interleaved + attributes of empty meshes. */ + if(_vertexCount) { + const UnsignedInt typeSize = + isVertexFormatImplementationSpecific(attribute._format) ? 0 : + (vertexFormatSize(attribute._format)* + (attribute._arraySize ? attribute._arraySize : 1)); + if(attribute._isOffsetOnly) { + const std::size_t size = attribute._data.offset + (_vertexCount - 1)*attribute._stride + typeSize; + CORRADE_ASSERT(size <= _vertexData.size(), + "Trade::MeshData: offset-only attribute" << i << "spans" << size << "bytes but passed vertexData array has only" << _vertexData.size(), ); + } else { + const void* const begin = static_cast(attribute._data.pointer); + const void* const end = static_cast(attribute._data.pointer) + (_vertexCount - 1)*attribute._stride + typeSize; + CORRADE_ASSERT(begin >= _vertexData.begin() && end <= _vertexData.end(), + "Trade::MeshData: attribute" << i << "[" << Debug::nospace << begin << Debug::nospace << ":" << Debug::nospace << end << Debug::nospace << "] is not contained in passed vertexData array [" << Debug::nospace << static_cast(_vertexData.begin()) << Debug::nospace << ":" << Debug::nospace << static_cast(_vertexData.end()) << Debug::nospace << "]", ); + } } } #endif