Search Unity

Entire Code Section not called in WebGL

Discussion in 'Web' started by JoshuaMcKenzie, Aug 19, 2019.

  1. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    So I'm developing a Game that has plans to be supported on multiple platforms. for the time being the only primary platform is WebGL. The game uses Firebase, which isn't supported by the SDK for WebGL, so we have to communicate to Firbase via Javascript with extern and SendMessage calls. That much works.

    I was confused as to why I was getting OnChildAdded called in the Editor (which uses the SDK), but not in WebGL.I thought it was a syntax error somewhere in my code. maybe the path was wrong... maybe the setter wasn't called... No! The main issue I'm seeing is because an entire if/else code block inside a property setter is completely skipped, yet the rest of the setter code is called.

    WebGL CodeBlock Skipped.png

    In the picture is the Console.log series of events that is happening I Issue a call to start tracking a property on Firebase via an adapter (which implementation will change depending on platform)
    Code (CSharp):
    1.         public bool IsTracking
    2.         {
    3.             get { return m_isTracking; }
    4.             set
    5.             {
    6.                 if(m_isTracking == value)
    7.                     return;
    8.  
    9.                 m_isTracking = value;
    10.  
    11.                 if(m_isTracking == true)
    12.                 {
    13.  
    14.                     Debug.Log("subscribing To OnChildAdded");
    15.                     FirebaseWebGlAdapter.OnChildAdded += OnVocabAdded;
    16.                     Debug.LogFormat("FirebaseWebGlAdapter.OnChildAdded is null = {0}",FirebaseWebGlAdapter.IsOnChildAddedNull());
    17.                     FirebaseWebGlAdapter.OnChildRemoved += OnVocabRemoved;
    18.                 }
    19.                 else
    20.                 {
    21.                     Debug.Log("unsubscribing To OnChildAdded");
    22.                     FirebaseWebGlAdapter.OnChildAdded -= OnVocabAdded;
    23.                     FirebaseWebGlAdapter.OnChildRemoved -= OnVocabRemoved;
    24.                     IsSynced = false;
    25.                 }
    26.  
    27.                 Debug.LogFormat("Tracking Path: {0}: {1}",m_path,value);
    28.  
    29.                 FirebaseWebGlAdapter.TrackProperty(m_path,value);
    30.             }
    31.         }
    The If/Else code block in this property setter is skipped. the only Debug log you see is the "Tracking Path", but nothing about OnChildAdded. This is the crux of the issue My Events don't get binded because of this, this makes FirebaseWebGlAdapter.OnChildAdded null (hence the "Not listening for FirebaseChildAdded" that was logged).

    I've been searching around looking to see if anyone ever had this issue before but I just can't figure out what implementation exactly is causing this problem... is it Firebase? (doubt it), WebGL?(unsure), Unity?, or C# itself? I wouldn't discount the possibility that its due to my implementation, but I've been combing the code for a few days and the only conclusion is that an entire section of valid, operational code is just getting optimized out. however cleaning/rebuilding the solution did not solve this...

    So how is my entire if/else block getting completely skipped?
     
  2. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    916
    I wasn't able to figure out the cause so I had to completely refactor it without using explicit events. Don't think events were the actual issue but just some glitch in the build.