fix deadlock

This commit is contained in:
ousttrue
2021-02-12 21:48:47 +09:00
parent c7e0191685
commit 6f3d3e3f2b
5 changed files with 39 additions and 16 deletions

View File

@@ -0,0 +1,21 @@
using System.Collections;
using System.Threading.Tasks;
namespace UniGLTF
{
public static class TaskExtensions
{
public static IEnumerator AsIEnumerator(this Task task)
{
while (!task.IsCompleted)
{
yield return null;
}
if (task.IsFaulted)
{
throw task.Exception;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54481e2d4da20ec4fa15376518f2e938
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -145,6 +145,7 @@ namespace UniGLTF
if (m_gltf.materials == null || m_gltf.materials.Count == 0)
{
var task = CreateMaterialAsync(m_gltf, 0, GetTextureAsync);
while (!task.IsCompleted)
{
yield return null;

View File

@@ -27,12 +27,10 @@ namespace UniGLTF
public static async Task<Texture2D> LoadTextureAsync(glTF gltf, IStorage storage, int index)
{
string m_textureName = default;
var imageBytes = await Task.Run(() =>
{
var imageIndex = gltf.GetImageIndexFromTextureIndex(index);
var segments = gltf.GetImageBytes(storage, imageIndex, out m_textureName);
return ToArray(segments);
});
var imageIndex = gltf.GetImageIndexFromTextureIndex(index);
var segments = gltf.GetImageBytes(storage, imageIndex, out m_textureName);
var imageBytes = ToArray(segments);
//
// texture from image(png etc) bytes

View File

@@ -55,16 +55,8 @@ namespace UniGLTF
public IEnumerator ProcessOnMainThread(glTF gltf, IStorage storage, bool isLinear, glTFTextureSampler sampler)
{
ArraySegment<Byte> bytes = default;
var task = Task.Run(() =>
{
var imageIndex = gltf.GetImageIndexFromTextureIndex(m_textureIndex);
bytes = gltf.GetImageBytes(storage, imageIndex, out m_textureName);
});
while (!task.IsCompleted)
{
yield return null;
}
var imageIndex = gltf.GetImageIndexFromTextureIndex(m_textureIndex);
var bytes = gltf.GetImageBytes(storage, imageIndex, out m_textureName);
// tmp file
var tmp = Path.GetTempFileName();