WebGL: RuntimeError: memory access out of bounds.
Hello to everybody, so im facing this error "Runtime Error: memory access out of bounds." when i run my webGL build on some mobile browsers.
These are my tests:
Fail: Chrome for android, version 87.0.4280.101 (latest stable until now);
Success: Firefox for android, version 84.1.1 (latest stable until now);
Fail: Safari for iOS (latest stable version);
Fail: Chrome for iOS (latest stable version);
Fail: Firefox for iOS (latest stable version);
On desktop, works correctly on any browser.
How do i generate this error:
Just by running a WWW or UnityWebRequest to download a file data like this:
byte[] data = null;
WWW www = new WWW(url);
yield return www;
if (www.error != null)
throw new Exception(www.error);
else
data = www.bytes;
print(www.text.Length);//Printing the text lenght give the error
print(data.Length);//Printing the bytes lenght doesnt give the error
Note: it happens only with files that are like 10/20MB or heavier, i've tried with a file that is less than 1MB and it works correctly on all the mobile browsers. I already read that a solution should be by increasing the memory allocation / memory heap, but i didnt understand how.
i already tried this and many other ways:
var maxHeapSize = 256 * 1024 * 1024;
UnityEditor.PlayerSettings.WebGL.emscriptenArgs = string.Format("-s WASM_MEM_MAX={0} -s ALLOW_MEMORY_GROWTH=1", maxHeapSize);
and this too:
UnityEditor.PlayerSettings.WebGL.memorySize = 1024;
But nothing changes, the error is still showing. And yes, i tried even with UnityWebRequest but still same error.
Ps: Actually i dont need to print the text lenght, but since i need to access to that string, the error will be given anyway even just for a simple access to the string (i guess its because the string is too large and so i should allocate memory first, BUT HOW?)
My Unity3D version is: 2020.1.10f1
Player settings > Other Settings:
Player settings > Publishing Settings:
Thanks to everyone who can help me.
I have a similar problem now. If you get an answer, then beep.
Update: i've tried with the latest stable version of unity (2021.1.15f1) and there is still the same problem. Someone can help me?
Thanks.
Answer by Pawciu · Jan 27, 2021 at 12:53 PM
I've finally fixed the same error in my project. Here is what i did:
1. Narrow down the line of code that crashes WebGL.
Go through the painfull process of pinpointing the line of code that is the source of the error. I had this "luck" that error occured when I've hit button and tried to load UIScene in Addition mode. So at first I found the script in the scene which when disabled got rid of the crash. Then I've repeated the steps and digged deeper into lines. After 2 hours of builds, comments etc I've found that the code was not working was setting the new color for UnityEngine.UI.Image. Which was pretty weird because in playmode everything worked ok.
2. Find solution.
I think my solution might not be universal but I think there is something going in the Unity gameloop/lifecycle when running WebGL. The source of the problem was that i set the field that was storing my UI.Image in the Start method and then in some function I've tried to change the color. Property was not exposed in inspector.
public class ModuleUI : MonoBehaviour
{
Image qualityBG;
void Start()
{
qualityBG = GetComponent<Image>();
}
then this line below was the cause of the crash
public void Set(Module module)
{
...
qualityBG.color = module.Quality.ToColor();
}
3. Fixing - so I've added [SerializeField] attribute to the field and set it up in editor, dragged the Image into the inspector slot. An it fixed it. I suspect that WebGL build might perform some methods in different order, or maybe the multipleScene loaded together might to do with it. I'm not sure but the field was not set properly with previous code fot WebGL build.
Bonus: I've also fixed some issues that was not critical (not crushing WebGL game) but not working properly as expected in playmode. This also has got to do with trying to set some object in Start() method and then doing something on them. The collection was not set up (probably null) in WebGL.
EffectUI[] effects;
Start()
{
effects = GetComponentsInChildren<EffectUI>();
}
void HideAllEffects()
{
if (effects != null)
for (int i = 0; i < effects.Length; ++i)
effects[i].gameObject.SetActive(false);
}
And this also started working when I've added [SerializeField] to effects and hook it up in the scene...
Hope this will help some of you guys & gals!
Answer by CTePeoTun · Dec 24, 2020 at 12:44 PM
I have a similar problem now. If you get an answer, then beep.
Answer by VRinteractive · Jan 07, 2021 at 10:18 AM
Up .
Update: i've tried with the latest stable version of unity (2021.1.15f1) and there is still the same problem. Someone can help me?
Thanks.
Answer by astrolabe-games · Mar 21 at 10:36 AM
in my case the problem was solved with the option "full without stacktrace" in the "enable exception field"
I tried Full Without Stacktrace
without any luck with Unity 2021.3.1f1.
It seems that WebGL builds are throwing "out of bounds memory access" runtime errors on my iPad (9th Generation) on iOS (15.4). I tested with Chrome and Safari.
I created a bare bones repro project. It's just an empty scene with a text label. https://github.com/tgraupmann/Unity2021TestWebGL
I did a development build for WebGL.
With Enable Exceptions: "Explicitly Thrown Exceptions Only" set https://theylovegames.com/Unity2021TestWebGL/
With Enable Exceptions: "Full Without Stacktrace" set https://theylovegames.com/Unity2021TestWebGL2/
It appears to work fine on PC and Android. The iPad is my only iOS device for testing.
I ran into other issues with the new 2021 build process that were not problems in 2020. I can't have UTF8 characters in the WebGL file, even in commented out code. Otherwise the build will fail. I had cache issues where I'd remove C# scripts and they were still being compiled by the WebGL build process. I had to close the editor and delete the Library folder to clear the cache.
This says the issue may be fixed in 2022.1.0a14
which is available in the Unity Hub under Pre-releases... 2022.2.0a10
is currently available. https://issuetracker.unity3d.com/issues/webgl-runtimeerror-memory-access-out-of-bounds-when-building-and-running-build
The errors still reproduce on the latest alpha.
2022.2.0a10 - Explicitly Thrown Exceptions Only - https://theylovegames.com/Unity2021TestWebGL_A1/
2022.2.0a10 - Mem128 - https://theylovegames.com/Unity2021TestWebGL_A2/
2022.2.0a10 - Full No Stack Trace - https://theylovegames.com/Unity2021TestWebGL_A3/
Answer by Damast · May 22 at 07:43 PM
Same problem Unity 2019.4.39f1 & 2022.2.0a13 "RuntimeError: Out of bounds memory access" Android, Chrome Desktop works, IOS fails
Your answer
Follow this Question
Related Questions
webgl project only runs in firefox 1 Answer
why i see black screen in any unity web game 0 Answers
[WebGL] UI drag in Edge browser 1 Answer
WebPlayer and WebGL wont work 1 Answer
WebGl on google sites? 0 Answers