Skip to content

Commit

Permalink
avoid exception in upload/download/write when count=0
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Sep 23, 2024
1 parent 3462a35 commit 21c2d1e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/Aardvark.Rendering/Resources/Adaptive/AdaptiveBuffer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ type AdaptiveBufferExtensions private() =
assert (start >= 0 && start < data.Length)
assert (start + length <= data.Length)

(start, data) ||> NativePtr.pinArri (fun src ->
let size = nativeint (length * sizeof<'T>)
this.Write(src.Address, offset, size)
if length > 0 then
(start, data) ||> NativePtr.pinArri (fun src ->
let size = nativeint (length * sizeof<'T>)
this.Write(src.Address, offset, size)
)

/// <summary>
Expand Down
21 changes: 12 additions & 9 deletions src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ type IBufferRangeExtensions private() =
srcIndex |> checkNonNegative "srcIndex"
(srcIndex, count) ||> checkArrayBounds src

(srcIndex, src) ||> NativePtr.pinArri (fun pSrc ->
dst.Buffer.Upload(dst.Offset + byteSize<'T> dstIndex, pSrc.Address, byteSize<'T> count)
)
if count > 0 then
(srcIndex, src) ||> NativePtr.pinArri (fun pSrc ->
dst.Buffer.Upload(dst.Offset + byteSize<'T> dstIndex, pSrc.Address, byteSize<'T> count)
)

///<summary>Copies elements from an array to a buffer range.</summary>
///<param name="dst">The buffer range to copy data to.</param>
Expand Down Expand Up @@ -186,9 +187,10 @@ type IBufferRangeExtensions private() =
dstIndex |> checkNonNegative "dstIndex"
(dstIndex, count) ||> checkArrayBounds dst

(dstIndex, dst) ||> NativePtr.pinArri (fun pDst ->
src.Buffer.Download(src.Offset + byteSize<'T> srcIndex, pDst.Address, byteSize<'T> count)
)
if count > 0 then
(dstIndex, dst) ||> NativePtr.pinArri (fun pDst ->
src.Buffer.Download(src.Offset + byteSize<'T> srcIndex, pDst.Address, byteSize<'T> count)
)

///<summary>Copies elements from a buffer range to an array.</summary>
///<param name="src">The buffer range to copy data from.</param>
Expand Down Expand Up @@ -249,9 +251,10 @@ type IBufferRangeExtensions private() =
dstIndex |> checkNonNegative "dstIndex"
(dstIndex, count) ||> checkArrayBounds dst

(dstIndex, dst) ||> NativePtr.pinArri (fun pDst ->
src.Buffer.DownloadAsync(src.Offset + byteSize<'T> srcIndex, pDst.Address, byteSize<'T> count)
)
if count > 0 then
(dstIndex, dst) ||> NativePtr.pinArri (fun pDst ->
src.Buffer.DownloadAsync(src.Offset + byteSize<'T> srcIndex, pDst.Address, byteSize<'T> count)

Check failure on line 256 in src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs

View workflow job for this annotation

GitHub Actions / build

Type constraint mismatch. The type � 'unit -> unit' �is not compatible with type� 'unit'

Check failure on line 256 in src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs

View workflow job for this annotation

GitHub Actions / build

Type constraint mismatch. The type � 'unit -> unit' �is not compatible with type� 'unit'

Check failure on line 256 in src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs

View workflow job for this annotation

GitHub Actions / build

Type constraint mismatch. The type � 'unit -> unit' �is not compatible with type� 'unit'

Check failure on line 256 in src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs

View workflow job for this annotation

GitHub Actions / build

Type constraint mismatch. The type � 'unit -> unit' �is not compatible with type� 'unit'

Check failure on line 256 in src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs

View workflow job for this annotation

GitHub Actions / build

Type constraint mismatch. The type � 'unit -> unit' �is not compatible with type� 'unit'

Check failure on line 256 in src/Aardvark.Rendering/Resources/Buffers/BufferExtensions.fs

View workflow job for this annotation

GitHub Actions / build

Type constraint mismatch. The type � 'unit -> unit' �is not compatible with type� 'unit'
)

///<summary>Asynchronously copies elements from a buffer range to an array.</summary>
///<param name="src">The buffer range to copy data from.</param>
Expand Down

0 comments on commit 21c2d1e

Please sign in to comment.