Browse Source

Trade: actually, do it like this.

pull/537/head
Vladimír Vondruš 5 years ago
parent
commit
5c06eecde8
  1. 19
      src/Magnum/Trade/MeshData.cpp

19
src/Magnum/Trade/MeshData.cpp

@ -133,30 +133,27 @@ MeshData::MeshData(const MeshPrimitive primitive, Containers::Array<char>&& inde
"Trade::MeshData: attribute" << i << "has" << attribute._vertexCount << "vertices but" << expectedAttributeVertexCount << "expected", ); "Trade::MeshData: attribute" << i << "has" << attribute._vertexCount << "vertices but" << expectedAttributeVertexCount << "expected", );
/* Check that the view fits into the provided vertex data array. For /* 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 implementation-specific formats we don't know the size so use 0 to
check at least partially. */ 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 = const UnsignedInt typeSize =
isVertexFormatImplementationSpecific(attribute._format) ? 0 : isVertexFormatImplementationSpecific(attribute._format) ? 0 :
(vertexFormatSize(attribute._format)* (vertexFormatSize(attribute._format)*
(attribute._arraySize ? attribute._arraySize : 1)); (attribute._arraySize ? attribute._arraySize : 1));
if(attribute._isOffsetOnly) { if(attribute._isOffsetOnly) {
const std::size_t size = attribute._data.offset + (_vertexCount - 1)*attribute._stride + typeSize; 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 CORRADE_ASSERT(size <= _vertexData.size(),
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(), ); "Trade::MeshData: offset-only attribute" << i << "spans" << size << "bytes but passed vertexData array has only" << _vertexData.size(), );
} else { } else {
const void* const begin = static_cast<const char*>(attribute._data.pointer); const void* const begin = static_cast<const char*>(attribute._data.pointer);
const void* const end = static_cast<const char*>(attribute._data.pointer) + (_vertexCount - 1)*attribute._stride + typeSize; const void* const end = static_cast<const char*>(attribute._data.pointer) + (_vertexCount - 1)*attribute._stride + typeSize;
/* For meshes with zero vertices we don't check the pointer, since CORRADE_ASSERT(begin >= _vertexData.begin() && end <= _vertexData.end(),
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<const void*>(_vertexData.begin()) << Debug::nospace << ":" << Debug::nospace << static_cast<const void*>(_vertexData.end()) << Debug::nospace << "]", ); "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<const void*>(_vertexData.begin()) << Debug::nospace << ":" << Debug::nospace << static_cast<const void*>(_vertexData.end()) << Debug::nospace << "]", );
} }
} }
}
#endif #endif
} }

Loading…
Cancel
Save