Skip to content

Commit

Permalink
fix: Not using unsupported System.Threading.Task.Run in WebGL builds (
Browse files Browse the repository at this point in the history
fixes #131)
  • Loading branch information
atteneder committed Feb 7, 2021
1 parent cc3c7a3 commit 02f45d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Had to bring back `GltfAsset.isDone` for render tests
### Fixed
- WebGL loading by not using unsupported `System.Threading.Task.Run` (fixes #131)
- Escaped, relative buffer/texture URIs now work on local file system consistently
- Rendertests work again

Expand Down
14 changes: 7 additions & 7 deletions Runtime/Scripts/GltFast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
// limitations under the License.
//

#if !UNITY_WEBGL || UNITY_EDITOR
#define GLTFAST_THREADS
#endif

// #define MEASURE_TIMINGS

using System;
Expand All @@ -36,10 +40,6 @@
using GLTFast.Tests;
#endif

#if KTX_UNITY

#endif // KTX_UNITY

[assembly: InternalsVisibleTo("glTFastEditorTests")]

namespace GLTFast {
Expand Down Expand Up @@ -285,7 +285,7 @@ async Task LoadContent() {
async Task<bool> ParseJsonAndLoadBuffers( string json, Uri baseUri ) {

var predictedTime = json.Length / (float)k_JsonParseSpeed;
#if !MEASURE_TIMINGS
#if GLTFAST_THREADS && !MEASURE_TIMINGS
if (deferAgent.ShouldDefer(predictedTime)) {
// JSON is larger than threshold
// => parse in a thread
Expand Down Expand Up @@ -749,14 +749,14 @@ void LoadBuffer( int index, Uri url ) {
async Task<Tuple<byte[],string>> DecodeEmbedBufferAsync(string encodedBytes,bool timeCritical = false) {
var predictedTime = encodedBytes.Length / (float)k_Base64DecodeSpeed;
#if MEASURE_TIMINGS
await deferAgent.BreakPoint(predictedTime);
var stopWatch = new Stopwatch();
stopWatch.Start();
#else
#elif GLTFAST_THREADS
if (!timeCritical || deferAgent.ShouldDefer(predictedTime)) {
return await Task.Run(() => DecodeEmbedBuffer(encodedBytes));
}
#endif
await deferAgent.BreakPoint(predictedTime);
var decodedBuffer = DecodeEmbedBuffer(encodedBytes);
#if MEASURE_TIMINGS
stopWatch.Stop();
Expand Down

0 comments on commit 02f45d4

Please sign in to comment.