diff --git a/sources/engine/Stride.Graphics/IndexBufferHelper.cs b/sources/engine/Stride.Graphics/IndexBufferHelper.cs index 1d93ef8800..515613bcc7 100644 --- a/sources/engine/Stride.Graphics/IndexBufferHelper.cs +++ b/sources/engine/Stride.Graphics/IndexBufferHelper.cs @@ -31,9 +31,18 @@ public readonly struct IndexBufferHelper public Span DataInner => DataOuter.AsSpan(Binding.Offset, Binding.Count * (Binding.Is32Bit ? 4 : 2)); /// - public IndexBufferHelper(IndexBufferBinding binding, IServiceRegistry services, out int count) + public IndexBufferHelper(IndexBufferBinding binding, IServiceRegistry services, out int count) + : this(binding, MeshExtension.FetchBufferContentOrThrow(binding.Buffer, services), out count) { - DataOuter = MeshExtension.FetchBufferContentOrThrow(binding.Buffer, services); + } + + /// + public IndexBufferHelper(IndexBufferBinding binding, byte[] dataOuter, out int count) + { + if (dataOuter.Length < binding.Offset + binding.Count * (binding.Is32Bit ? 4 : 2)) + throw new ArgumentException($"Binding describes an array larger than {nameof(dataOuter)} ({dataOuter.Length} < {binding.Offset} + {binding.Count} * {(binding.Is32Bit ? 4 : 2)})"); + + DataOuter = dataOuter; Binding = binding; count = Binding.Count; } diff --git a/sources/engine/Stride.Graphics/VertexBufferBinding.cs b/sources/engine/Stride.Graphics/VertexBufferBinding.cs index c7484efeb0..ecc2c46b0a 100644 --- a/sources/engine/Stride.Graphics/VertexBufferBinding.cs +++ b/sources/engine/Stride.Graphics/VertexBufferBinding.cs @@ -46,7 +46,7 @@ public VertexBufferBinding(Buffer vertexBuffer, VertexDeclaration vertexDeclarat public Buffer Buffer { get; private set; } /// - /// Gets the offset (vertex index) between the beginning of the buffer and the vertex data to use. + /// Gets the offset in bytes between the beginning of the buffer and the vertex data to use. /// public int Offset { get; private set; } diff --git a/sources/engine/Stride.Graphics/VertexBufferHelper.cs b/sources/engine/Stride.Graphics/VertexBufferHelper.cs index 926877837d..1b1c9dadaa 100644 --- a/sources/engine/Stride.Graphics/VertexBufferHelper.cs +++ b/sources/engine/Stride.Graphics/VertexBufferHelper.cs @@ -51,7 +51,7 @@ public VertexBufferHelper(VertexBufferBinding binding, IServiceRegistry services public VertexBufferHelper(VertexBufferBinding binding, byte[] dataOuter, out int count) { if (dataOuter.Length < binding.Offset + binding.Count * binding.Stride) - throw new ArgumentException($"{nameof(dataOuter)} does not fit the bindings provided. Make sure that the span provided contains the entirety of the vertex buffer"); + throw new ArgumentException($"Binding describes an array larger than {nameof(dataOuter)} ({dataOuter.Length} < {binding.Offset} + {binding.Count} * {binding.Stride})"); DataOuter = dataOuter; Binding = binding;