Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question WebXR build on WebGL Runtime error

Discussion in 'Web' started by bigvalthoss, Jun 6, 2021.

  1. bigvalthoss

    bigvalthoss

    Joined:
    May 26, 2020
    Posts:
    23
    Hello,

    I have a function that loads in a 3D texture from a byte data file. It is quite a large file (512 x 256 x 512 voxels). I am using a web request to read the file contents. Everything works on the editor, but fails when running on the webGL build. Here is the stack trace:

    Code (csharp):
    1. //127.0.0.1:8080/Build/Build.framework.js:27569:40)
    2.     at invoke_iiiii (https://127.0.0.1:8080/Build/Build.framework.js:18109:33)
    3.     at __ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException (<anonymous>:wasm-function[33674]:0xb6077c)
    4.     at _il2cpp_runtime_invoke (<anonymous>:wasm-function[32638]:0xb3dc3f)
    5.     at __Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb (<anonymous>:wasm-function[5397]:0x1dd589)
    6.     at __ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb (<anonymous>:wasm-function[5394]:0x1dd0e3)
    7.     at __ZN9Coroutine14InvokeMoveNextEP21ScriptingExceptionPtr (<anonymous>:wasm-function[10194]:0x36f5d0)
    8.     at __ZN9Coroutine3RunEPb (<anonymous>:wasm-function[10191]:0x36f292)
    9.     at __ZN9Coroutine17ContinueCoroutineEP6ObjectPv (<anonymous>:wasm-function[10197]:0x36f80f)
    10.     at __ZN14AsyncOperation15InvokeCoroutineEv (<anonymous>:wasm-function[11239]:0x3d75de)
    11.     at __ZN29UnityWebRequestAsyncOperation15InvokeCoroutineEv (<anonymous>:wasm-function[25408]:0x9ef6df)
    12.     at __ZN20UnityWebRequestProtoI24UnityWebRequestTransport16AtomicRefCounter14RedirectHelper14ResponseHelper15DownloadHandler13UploadHandler18CertificateHandler12HeaderHelper14AsyncOperationE19Job_InvokeCoroutineEPS8_ (<anonymous>:wasm-function[25380]:0x9ee4bc)
    13.     at __ZN18BackgroundJobQueue21ExecuteMainThreadJobsEv (<anonymous>:wasm-function[12924]:0x46f07f)
    14.     at __ZZ23InitPlayerLoopCallbacksvEN43EarlyUpdateExecuteMainThreadJobsRegistrator7ForwardEv (<anonymous>:wasm-function[13089]:0x484922)
    15.     at __Z17ExecutePlayerLoopP22NativePlayerLoopSystem (<anonymous>:wasm-function[12566]:0x447756)
    16.     at __Z17ExecutePlayerLoopP22NativePlayerLoopSystem (<anonymous>:wasm-function[12566]:0x44776b)
    17.     at __Z10PlayerLoopv (<anonymous>:wasm-function[12551]:0x4466e7)
    18.     at __ZL8MainLoopv (<anonymous>:wasm-function[12539]:0x4447c2)
    19.     at dynCall_v (<anonymous>:wasm-function[59305]:0xffbea3)
    20.     at Object.dynCall_v (https://127.0.0.1:8080/Build/Build.framework.js:27929:36)
    21.     at browserIterationFunc (https://127.0.0.1:8080/Build/Build.framework.js:10519:23)
    22.     at Object.runIter (https://127.0.0.1:8080/Build/Build.framework.js:10621:5)
    23.     at Browser_mainLoop_runner (https://127.0.0.1:8080/Build/Build.framework.js:10557:20)
     
  2. bigvalthoss

    bigvalthoss

    Joined:
    May 26, 2020
    Posts:
    23
    For some reason, it shortened the trace. Here is a picture of it.
     

    Attached Files:

  3. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
  4. bigvalthoss

    bigvalthoss

    Joined:
    May 26, 2020
    Posts:
    23
    I appreciate your response. I am a little unsure about how to do that. I have a script that creates a texture of a DICOM image (like a CT scan or MRI scan). It uses a raw byte data file, passes it through a color transfer function to get a Color[] array, it then uses the color array to create the texture. Note that the color transfer function sometimes changes, which is why we need it to be loaded in instead of saved as a unity texture.

    Here is the script I am using. I gave more context to what I am doing in case you know a better way.

    Code (CSharp):
    1.  
    2.     private IEnumerator LoadDataRoutine()
    3.     {
    4.         UnityWebRequest www = UnityWebRequest.Get(FullPathRawFile);
    5.  
    6.         yield return www.SendWebRequest();
    7.  
    8.         if (www.result != UnityWebRequest.Result.Success)
    9.         {
    10.             Debug.Log(www.error);
    11.         }
    12.         else
    13.         {
    14.             Debug.Log("raw file successful");
    15.             Color[] colors = LoadData(www.downloadHandler.data);
    16.             _volumeBuffer.Add(new Texture3D(dim[0], dim[1], dim[2], TextureFormat.RGBAHalf, mipmap));
    17.  
    18.             _volumeBuffer[0].SetPixels(colors);
    19.             _volumeBuffer[0].Apply();
    20.         }
    21.         DoneLoadingFileEvent.Invoke();
    22.     }
    23. }
    24.  
    Would what you are saying work to load and parse a raw data file?
     
  5. bigvalthoss

    bigvalthoss

    Joined:
    May 26, 2020
    Posts:
    23
    I also have another object that loads in 90 such textures into the _volumeBuffer variable so that we can play a video of a heart pumping.
     
  6. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    It's too much data for the current implementation of WebAssembly in browsers.
    Better do the decoding in JS and feed the texture to Unity using the Texture.GetNativeTexturePtr()
     
  7. bigvalthoss

    bigvalthoss

    Joined:
    May 26, 2020
    Posts:
    23
    Hmm.. Okay, thank you for the pointer. I will have to figure out how to do that :).