- Home /
(URGENT!!!!!!!!!) WebGL out of memory no matter how much I allocate. [C#]
Hey all! (mildly panicking)
I entered a game development competition last night, only to find out that my game wasn't working at all. Whenever a certain section of code was being run, the player would say "Out of memory!" I increased the memory allocation from the default 256 all the way up to 2048, and it still would not work. Any other values didn't work at all.
~ Unity WebGL player, 2019"Bad initial memory size"
I did some Debug.Log
ing and found that the code never makes it past this section:
string lwag = "";
for (int i = 0; i < 18;)
{
for (int j = 0; j < 3;)
{
lwag = lwag + levelsWithAllGems[i, j].ToString() + ".";
}
}
lwag = lwag.Substring(0, 107);
PlayerPrefs.SetString("LevelsWithAllGems", lwag);
Basically, I have an array int[18,3]
that I am trying to convert into a string, remove the last period, and set it to PlayerPrefs for a later date. However, it's just not working!
Please help as judging is underway and I should probably finish this before then.
Answer by xxmariofer · Mar 05, 2019 at 11:33 PM
you are never increasing i and j value so both fors are infinite loops.
Well I'm really stupid. Thank you so much for pointing it out, I thought they would always increment by one unless otherwise specified.
Just out of curiosity, didn't you test your game in the editor? This should have caused the editor to hang / not respond anymore.
Apart from that this line:
lwag = lwag + levelsWithAllGems[i, j].ToString() + ".";
is horrible for memory and garbage allocation. You usually would use a StringBuilder in such a case
StringBuilder sb = new StringBuilder(108);
for (int i = 0; i < 18; i++)
{
for (int j = 0; j < 3; j++)
{
sb.Append(levelsWithAllGems[i, j].ToString()).Append(".");
}
}
sb.Length = 107;
lwag = sb.ToString();
Your answer
Follow this Question
Related Questions
Downloading an image via WebGL 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity version, WebPlayer, WebGL related inquiries 0 Answers
Is there a way to send an XMLHttpRequest and get the response in a WWW object? 0 Answers