UnityGLTF icon indicating copy to clipboard operation
UnityGLTF copied to clipboard

WebGL run fails with failed thread creation

Open FreakTheMighty opened this issue 7 years ago • 23 comments

I've built from UnityGLTF from master, added the GLTFComponentto a scene to load a remote GLTF and disabled multithreading. When I built to WebGL I get the following error. I've found that the 1.0.0 release builds and runs in webgl.

Related: #138

SystemException: Thread creation failed.
UnityLoader.js:1043   at System.Threading.Thread.StartInternal (System.Security.Principal.IPrincipal principal, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0 
UnityLoader.js:1043 Rethrow as TypeInitializationException: The type initializer for 'System.Threading.Timer.Scheduler' threw an exception.
UnityLoader.js:1043 
UnityLoader.js:1043 Rethrow as TypeInitializationException: The type initializer for 'System.Threading.Timer' threw an exception.
UnityLoader.js:1043   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
UnityLoader.js:1043 --- End of stack trace from previous location where exception was thrown ---
UnityLoader.js:1043   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
UnityLoader.js:1043 --- End of stack trace from previous location where exception was thrown ---
UnityLoader.js:1043   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
UnityLoader.js:1043 --- End of stack trace from previous location where exception was thrown ---
UnityLoader.js:1043   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 
UnityLoader.js:1043 --- End of stack trace from previous location where exception was thrown ---
UnityLoader.js:1043   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0 

FreakTheMighty avatar Jan 31 '19 03:01 FreakTheMighty

Apologies, forgot platform information:

Unity 2018.3.1f1 OS X: 10.14.2 master @ bb189f382697317321a583b22f0aab3692414366

FreakTheMighty avatar Jan 31 '19 03:01 FreakTheMighty

I've just tried and I have the same thread creation errors. Unity 2018.3.3f1 Windows 10

it says also: "(Filename: currently not available on il2cpp Line: -1)"

kolodi avatar Jan 31 '19 08:01 kolodi

@kolodi that's interesting. I assumed it was because WebGL doesn't support threads. With that said, I had disabled multithreading and removed a Task.Delay that I thought might have been the cause and I still got the error.

FreakTheMighty avatar Jan 31 '19 19:01 FreakTheMighty

@kolodi that's interesting. I assumed it was because WebGL doesn't support threads. With that said, I had disabled multithreading and removed a Task.Delay that I thought might have been the cause and I still got the error.

I think it is web client (from .net) which can also use multithreading as it is one from the .net and not the standard unitywebrequest

kolodi avatar Jan 31 '19 19:01 kolodi

We have not tested with WebGL. If the Task libraries are not allowed, we will have to rework this. WebGL support is likely going to be on our roadmap very soon.

blgrossMS avatar Feb 12 '19 02:02 blgrossMS

Nice to hear. I have several projects to target stand alone, mobile and WebGL platforms. For now I am forced to use asset bundles. If I could use GLB on all platforms it would be a huge benefit. I could contribute in making http handler compatible with WebGL, for example based on UnityWebRequest...

kolodi avatar Feb 12 '19 06:02 kolodi

We have a slightly modified version of the app running on WebGL.

You can try this:

  • Revert WebRequestLoader.cs to this version: https://github.com/KhronosGroup/UnityGLTF/blob/83d267f2616585fc8aba5391c003c9a5538ada97/UnityGLTF/Assets/UnityGLTF/Scripts/Loader/WebRequestLoader.cs

  • Alter this line https://github.com/KhronosGroup/UnityGLTF/blob/bb189f382697317321a583b22f0aab3692414366/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs#L100 to loader = new WebRequestLoader(directoryPath, asyncCoroutineHelper);

  • And this line https://github.com/KhronosGroup/UnityGLTF/blob/ce8485e3b982d1349f1b4b086cba421faf9b11fb/UnityGLTF/Assets/UnityGLTF/Examples/MultiSceneComponent.cs#L24 to loader = new WebRequestLoader(directoryPath, _asyncCoroutineHelper);

  • Disable the Multithreaded property from the GLTFComponent.

edumlauer avatar Feb 14 '19 15:02 edumlauer

@edumlauer how as the performance been for you? I don't have any benchmarks to report, but generally I've found its very slow to load even small models.

FreakTheMighty avatar Feb 14 '19 17:02 FreakTheMighty

@edumlauer how as the performance been for you? I don't have any benchmarks to report, but generally I've found its very slow to load even small models.

We use glbs with mesh data only, we dont' have textures on them.

Loading models from disk:

  • 857 KB - 355 ms
  • 15 MB - 2000 ms
  • 82 MB - 6500 ms

I don't have anything to compare with to say wether its fast or not, but it has been good enough for us.

edumlauer avatar Feb 14 '19 18:02 edumlauer

@edumlauer how as the performance been for you? I don't have any benchmarks to report, but generally I've found its very slow to load even small models.

We use glbs with mesh data only, we dont' have textures on them.

Loading models from disk:

  • 857 KB - 355 ms
  • 15 MB - 2000 ms
  • 82 MB - 6500 ms

I don't have anything to compare with to say wether its fast or not, but it has been good enough for us.

I realize now that this tests were made in the editor, so I'm not sure how they compare to a webgl build. But as I said earlier results in general have been great, the thing that contributes to slower load times are download speeds that vary for each user.

edumlauer avatar Feb 14 '19 18:02 edumlauer

We have a slightly modified version of the app running on WebGL.

It seems to download now, but I have another exception: ShaderNotFoundException: GLTF/PbrMetallicRoughness not found. Did you forget to add it to the build? I have a GLB file to download with PBR materials. It works fine in the editor, but the shader is not included then in the build. How can I be sure to include all the necessary shaders for every possible model?

kolodi avatar Feb 15 '19 07:02 kolodi

So I have included 2 shaders in the graphics settings

  1. PbrMetallicRoughness
  2. PbrSpecularGlossiness Then I was waiting for like 3 hours for building, then I realize that it repeats "compiling shader variants" infinitely:

kolodi avatar Feb 15 '19 09:02 kolodi

We have a slightly modified version of the app running on WebGL.

You can try this:

  • Revert WebRequestLoader.cs to this version: https://github.com/KhronosGroup/UnityGLTF/blob/83d267f2616585fc8aba5391c003c9a5538ada97/UnityGLTF/Assets/UnityGLTF/Scripts/Loader/WebRequestLoader.cs

  • Alter this line

      [UnityGLTF/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs](https://github.com/KhronosGroup/UnityGLTF/blob/bb189f382697317321a583b22f0aab3692414366/UnityGLTF/Assets/UnityGLTF/Scripts/GLTFComponent.cs#L100)
    
    
         Line 100
      in
      [bb189f3](/KhronosGroup/UnityGLTF/commit/bb189f382697317321a583b22f0aab3692414366)
    
    
    
    
    
    
    
           loader = new WebRequestLoader(directoryPath); 
    

    to loader = new WebRequestLoader(directoryPath, asyncCoroutineHelper);

  • And this line

      [UnityGLTF/UnityGLTF/Assets/UnityGLTF/Examples/MultiSceneComponent.cs](https://github.com/KhronosGroup/UnityGLTF/blob/ce8485e3b982d1349f1b4b086cba421faf9b11fb/UnityGLTF/Assets/UnityGLTF/Examples/MultiSceneComponent.cs#L24)
    
    
         Line 24
      in
      [ce8485e](/KhronosGroup/UnityGLTF/commit/ce8485e3b982d1349f1b4b086cba421faf9b11fb)
    
    
    
    
    
    
    
           _loader = new WebRequestLoader(directoryPath); 
    

    to loader = new WebRequestLoader(directoryPath, _asyncCoroutineHelper);

  • Disable the Multithreaded property from the GLTFComponent.

@edumlauer Can we merge this to the master wrapping the solution for the WebGL with #if UNITY_WEBGL so everyone can use it and close this issue?

kolodi avatar Feb 15 '19 15:02 kolodi

Yeah, it would be great if you could send out a PR. We could get it merged quickly :)

blgrossMS avatar Feb 15 '19 16:02 blgrossMS

Yeah, it would be great if you could send out a PR. We could get it merged quickly :)

Ok, I'm gonna work on it

kolodi avatar Feb 15 '19 16:02 kolodi

So I have included 2 shaders in the graphics settings

  1. PbrMetallicRoughness
  2. PbrSpecularGlossiness Then I was waiting for like 3 hours for building, then I realize that it repeats "compiling shader variants" infinitely:

Why is that build process so miserable?

FreakTheMighty avatar Feb 15 '19 17:02 FreakTheMighty

So I have included 2 shaders in the graphics settings

  1. PbrMetallicRoughness
  2. PbrSpecularGlossiness Then I was waiting for like 3 hours for building, then I realize that it repeats "compiling shader variants" infinitely:

Why is that build process so miserable?

The Scene Loader for some reason wants to use always those 2 shaders for every loaded 3d model even if the model was made using simple unity default shaders. That is really strange. And you should include those 2 shaders in the graphics settings in order to have them in the build. Now building takes ages to compile thousands of shader variants.

kolodi avatar Feb 18 '19 09:02 kolodi

Yeah, it would be great if you could send out a PR. We could get it merged quickly :)

I have made necessary changes to solve the issue, but I can't publish the new branch with the fix to be able to make a PR.

kolodi avatar Feb 18 '19 10:02 kolodi

You should be able to fork the repo and create a branch that will allow you to submit a PR (see https://guides.github.com/activities/forking/)

ericob avatar Feb 25 '19 22:02 ericob

You should be able to fork the repo and create a branch that will allow you to submit a PR (see https://guides.github.com/activities/forking/)

Ok, please review my PR

kolodi avatar Feb 27 '19 08:02 kolodi