add debug check for zero length buffer copy
parent
f298a5ec11
commit
088e7c4b6f
|
@ -1718,10 +1718,6 @@ namespace MoonWorks.Graphics
|
||||||
uint bufferOffsetInBytes = 0
|
uint bufferOffsetInBytes = 0
|
||||||
) where T : unmanaged
|
) where T : unmanaged
|
||||||
{
|
{
|
||||||
#if DEBUG
|
|
||||||
AssertRenderPassInactive("Cannot copy during render pass!");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
SetBufferData(
|
SetBufferData(
|
||||||
buffer,
|
buffer,
|
||||||
data,
|
data,
|
||||||
|
@ -1770,6 +1766,7 @@ namespace MoonWorks.Graphics
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertRenderPassInactive("Cannot copy during render pass!");
|
AssertRenderPassInactive("Cannot copy during render pass!");
|
||||||
|
AssertNonEmptyCopy(dataLengthInBytes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Refresh.Refresh_SetBufferData(
|
Refresh.Refresh_SetBufferData(
|
||||||
|
@ -1799,13 +1796,15 @@ namespace MoonWorks.Graphics
|
||||||
uint numElements
|
uint numElements
|
||||||
) where T : unmanaged
|
) where T : unmanaged
|
||||||
{
|
{
|
||||||
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
|
var dataLengthInBytes = (uint) (elementSize * numElements);
|
||||||
|
var dataOffsetInBytes = (int) startElement * elementSize;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertRenderPassInactive("Cannot copy during render pass!");
|
AssertRenderPassInactive("Cannot copy during render pass!");
|
||||||
|
AssertNonEmptyCopy(dataLengthInBytes);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
var elementSize = Marshal.SizeOf<T>();
|
|
||||||
var dataOffsetInBytes = (int) startElement * elementSize;
|
|
||||||
|
|
||||||
fixed (T* ptr = data)
|
fixed (T* ptr = data)
|
||||||
{
|
{
|
||||||
Refresh.Refresh_SetBufferData(
|
Refresh.Refresh_SetBufferData(
|
||||||
|
@ -1814,7 +1813,7 @@ namespace MoonWorks.Graphics
|
||||||
buffer.Handle,
|
buffer.Handle,
|
||||||
bufferOffsetInBytes,
|
bufferOffsetInBytes,
|
||||||
(IntPtr) ptr + dataOffsetInBytes,
|
(IntPtr) ptr + dataOffsetInBytes,
|
||||||
(uint) (numElements * elementSize)
|
dataLengthInBytes
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1844,18 +1843,23 @@ namespace MoonWorks.Graphics
|
||||||
IntPtr dataPtr,
|
IntPtr dataPtr,
|
||||||
uint bufferOffsetInElements,
|
uint bufferOffsetInElements,
|
||||||
uint numElements
|
uint numElements
|
||||||
) where T : unmanaged {
|
) where T : unmanaged
|
||||||
|
{
|
||||||
|
var elementSize = Marshal.SizeOf<T>();
|
||||||
|
var dataLengthInBytes = (uint) (elementSize * numElements);
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
AssertRenderPassInactive("Cannot copy during render pass!");
|
AssertRenderPassInactive("Cannot copy during render pass!");
|
||||||
|
AssertNonEmptyCopy((uint) (elementSize * numElements));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Refresh.Refresh_SetBufferData(
|
Refresh.Refresh_SetBufferData(
|
||||||
Device.Handle,
|
Device.Handle,
|
||||||
Handle,
|
Handle,
|
||||||
buffer.Handle,
|
buffer.Handle,
|
||||||
(uint) Marshal.SizeOf<T>() * bufferOffsetInElements,
|
(uint) elementSize * bufferOffsetInElements,
|
||||||
dataPtr,
|
dataPtr,
|
||||||
(uint) Marshal.SizeOf<T>() * numElements
|
dataLengthInBytes
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2197,6 +2201,14 @@ namespace MoonWorks.Graphics
|
||||||
throw new System.ArgumentException("The bound Texture's UsageFlags must include TextureUsageFlags.Sampler!");
|
throw new System.ArgumentException("The bound Texture's UsageFlags must include TextureUsageFlags.Sampler!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AssertNonEmptyCopy(uint dataLengthInBytes)
|
||||||
|
{
|
||||||
|
if (dataLengthInBytes == 0)
|
||||||
|
{
|
||||||
|
throw new System.InvalidOperationException("SetBufferData must have a length greater than 0 bytes!");
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue