mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-11 13:29:41 -05:00
fix deadlock
This commit is contained in:
21
Assets/UniGLTF/Runtime/Extensions/TaskExtensions.cs
Normal file
21
Assets/UniGLTF/Runtime/Extensions/TaskExtensions.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/UniGLTF/Runtime/Extensions/TaskExtensions.cs.meta
Normal file
11
Assets/UniGLTF/Runtime/Extensions/TaskExtensions.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54481e2d4da20ec4fa15376518f2e938
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user