Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tiny 3rd party API requests / iframes bug(?)

Discussion in 'Project Tiny' started by Maras, Jan 30, 2020.

  1. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    131
    When I call a js function which does a webpage request from Tiny, the request is triggered but gets canceled. For example, loading an iframe and appending it does not finish loading the src webpage.

    I narrowed down the issue:
    - It works in regular Unity (call triggered from a button, same library)
    - Calling the function from console works
    - It works OnStartRunning, before the game is properly started (not later, for example by enabling system manually)
    - It is not a context/caller issue
    - It seems it is not about returning the control to the caller, since await sleep() after the URL request does not help.

    There are two workarounds, both pretty bad:
    - setTimeout or await sleep() with long enough delay at the start of the function (one frame?). Usually, 200ms works with all the debug messages and input checking.
    - throwing at the end of the js function

    This is related, but the question is too broad: https://forum.unity.com/threads/unity-playtomic-interaction.818259/

    Can you please explain to me what is going on and how to solve this issue properly?
    Thanks!

    EDIT: Found the issue: https://forum.unity.com/threads/tiny-3rd-party-api-requests-iframes-bug.819057/#post-5437542
     
    Last edited: Feb 3, 2020
  2. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    131
    It seems the problem is actually audio - it looks like it cancels all requests and that might be the reason why even the textures are missing when you click too soon during menu in the Tiny Racing demo: https://tiny.vision/demos/TinyRacing/Wasm/TinyRacing.html

    I will investigate further today.
     
  3. Maras

    Maras

    Joined:
    Dec 11, 2012
    Posts:
    131
    The issue is AudioHTML.js, line 232 and 240:


    Code (CSharp):
    1.         // stop audio source node if it is already playing
    2.         this.stop(audioSourceIdx, true);

    The this.stop is actually window.stop() which cancels all requests and is indeed blocking even the textures from getting loaded.


    To fix, you could replace the lines in Unity.Tiny.Audio.Web, file AudioHTML.js with something like this:

    Code (CSharp):
    1.         if (this.audioSources[audioSourceIdx] === undefined){
    2.             // store audio source node
    3.             this.audioSources[audioSourceIdx] = sourceNode;          
    4.          
    5.         } else {
    6.             // stop audio source node if it is already playing
    7.             this.audioSources[audioSourceIdx].stop();
    8.          
    9.         }      
    10.      
    11.         sourceNode.onended = function (event) {
    12.             sourceNode.stop();
    13.             sourceNode.isPlaying = false;
    14.         };
     
    Last edited: Feb 3, 2020
    tonialatalo likes this.
  4. kevinmv

    kevinmv

    Unity Technologies

    Joined:
    Nov 15, 2018
    Posts:
    51
    Thanks for digging into this! You are correct this is a bug on our end which I'll patch now.
     
    tonialatalo and Maras like this.