Forum Scripting WebGL and an infinite loop. (Moved here)

Post your problems and discussions relating to scripting in Unity here.

WebGL and an infinite loop. (Moved here)

Postby Benedani » October 14th, 2017, 8:31 pm

I'm getting constant 66% CPU usage (two cores) and a browser freeze which I'm assuming is an infinite loop in the code. It works perfectly in the exe version though. This is the code that is causing issues:

Code: Select all
PlayerIO.QuickConnect.SimpleConnect(gameId, "guest", "guest", null, delegate (Client c)
        {
            guest = c;
            int n = PlayerPrefs.GetInt("rememberstatus", -1);
            //Debug.Log(n);
            c.BigDB.Load("Data", "Staff", delegate (DatabaseObject obj)
            {
                staff = obj;
            });
            c.BigDB.Load("Data", "Misc", delegate (DatabaseObject obj)
            {
                string nver = obj.GetString("cversion");
                if (nver == ver)
                {
                    if (n > 0)
                    {
                        transform.Find("RegisterLogonPanel").Find("UpdateCheck").Find("Text").GetComponent<Text>().text = "Connecting to lobby...";
                        logname.GetComponent<InputField>().text = PlayerPrefs.GetString("emailname", "");
                        logpass.GetComponent<InputField>().text = PlayerPrefs.GetString("pass", "");
                        logpass.parent.Find("Toggle").GetComponent<Toggle>().isOn = n == 1;
                        Login();
                        if (n == 2) PlayerPrefs.SetInt("rememberstatus", 0);
                    }
                    else
                    {
                        SetRegLogMenu(1);
                    }
                }
                else
                {
                    transform.Find("RegisterLogonPanel").Find("UpdateCheck").Find("Text").GetComponent<Text>().text = "An update has been found!\nCurrent version: " + ver + "\nNew version: " + nver;
                    transform.Find("RegisterLogonPanel").Find("UpdateCheck").Find("Button").GetComponent<RectTransform>().localScale = new Vector2(1, 1);
                }
            });
            foreach (Transform tr in transform.Find("VisibleArea").Find("GamesTab"))
            {
                if (tr.name != "0") // 0 is hardcoded
                {
                    c.BigDB.Load("Games", tr.name, delegate (DatabaseObject obj)
                    {
                        string name = obj.GetString("name");
                        string desc = obj.GetString("description");
                        string ownerid = obj.GetString("owner");
                        c.BigDB.Load("PlayerObjects", ownerid, delegate (DatabaseObject obj2)
                        {
                            string ownername = obj2.GetString("name");
                            tr.Find("Panel").Find("Text").GetComponent<Text>().text = name;
                            string colorcode = "#FFFFFF";
                            object a;
                            if (staff.TryGetValue(ownerid, out a))
                                colorcode = "#FF0000";
                            tr.Find("Panel2").Find("Text").GetComponent<Text>().text = "By: <b><color=" + colorcode + ">" + ownername + "</color></b>";
                            tr.Find("Text").GetComponent<Text>().text = desc;
                        }, delegate (PlayerIOError e)
                        {
                            Debug.LogError(e);
                        });
                    });
                }
            }
            foreach (Transform tr in transform.Find("VisibleArea").Find("AvatarTab").Find("Shirts"))
            {
                if (tr.name.StartsWith("Panel"))
                {
                    int id = int.Parse(tr.name.Remove(0, 5));
                    tr.GetComponent<Button>().onClick.RemoveAllListeners();
                    tr.GetComponent<Button>().onClick.AddListener(new UnityEngine.Events.UnityAction(() => ApplyClothing(clothstorage.clothes[id])));
                    RenderClothing(tr, id);
                    Thread.Sleep(50);
                }
            }
            foreach (Transform tr in transform.Find("VisibleArea").Find("AvatarTab").Find("Pants"))
            {
                if (tr.name.StartsWith("Panel"))
                {
                    int id = int.Parse(tr.name.Remove(0, 5));
                    tr.GetComponent<Button>().onClick.RemoveAllListeners();
                    tr.GetComponent<Button>().onClick.AddListener(new UnityEngine.Events.UnityAction(() => ApplyClothing(clothstorage.clothes[id])));
                    RenderClothing(tr, id);
                    Thread.Sleep(50);
                }
            }
            if (n == -1)
                PlayerPrefs.SetInt("rememberstatus", 0);
        });


Because the frozen frame is Checking for update..., I'm assuming it's to do with that part of the code. I mean, I could remove the update checker, but I mean it's a BigDB load so it should work. Though something else can be faulty too. Could someone check it?
Benedani
 
Posts: 12
Joined: March 28th, 2017, 5:10 pm

Return to Scripting



cron