From 062d6e33b5095d78efa678477cb85966bc0ea86b Mon Sep 17 00:00:00 2001 From: Kochoyume <78918084+kochounoyume@users.noreply.github.com> Date: Wed, 1 Jan 2025 16:00:49 +0900 Subject: [PATCH] Fix NativeArrayContent --- .../Runtime/WebRequest/NativeArrayContent.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Packages/MinimalUtility/Runtime/WebRequest/NativeArrayContent.cs b/Packages/MinimalUtility/Runtime/WebRequest/NativeArrayContent.cs index c365c07..1259745 100644 --- a/Packages/MinimalUtility/Runtime/WebRequest/NativeArrayContent.cs +++ b/Packages/MinimalUtility/Runtime/WebRequest/NativeArrayContent.cs @@ -1,8 +1,12 @@ -using System; +#if ENABLE_WEBREQUEST && ENABLE_UNITASK +#nullable enable + +using System; using System.IO; using System.Net; using System.Net.Http; using System.Threading.Tasks; +using Cysharp.Threading.Tasks; using Unity.Collections; namespace MinimalUtility.WebRequest @@ -21,10 +25,12 @@ public NativeArrayContent(NativeArray.ReadOnly data, IDisposable handler) _handler = handler; } - protected override Task SerializeToStreamAsync(Stream stream, TransportContext _) + protected override async Task SerializeToStreamAsync(Stream stream, TransportContext _) { - stream.Write(_data.AsReadOnlySpan()); - return Task.CompletedTask; + await using (UniTask.ReturnToMainThread()) + { + stream.Write(_data.AsReadOnlySpan()); + } } protected override bool TryComputeLength(out long length) @@ -42,4 +48,5 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } } -} \ No newline at end of file +} +#endif \ No newline at end of file