Skip to main content

The Unity webgl version crashes and prompts Memory access out of bounds. A series of huge pitfalls.

As shown in the picture above, this is really a huge pit. Only Firefox can open it normally. Other browsers report the above error. Baidu, circumventing the firewall, and searching for various ways to solve it have no results. I just came to the conclusion that there is N types of reasons may cause this problem to occur.

Since I don’t know the cause of the problem, I can only test it myself. After trying countless ascetic journeys of resource optimization and packaging testing, I found that even if there is only an empty scene with only one cube object in it, the same error will be reported after packaging it. .

After further packaging testing, the culprit was finally discovered, which was caused by the original standard shader that comes with Unity.

After repeated attempts, it was determined that the shader carries too many texture channels, so some browsers do not support it. The shader supported by most browsers can carry up to 3 texture channels. Replace the shader with one written by yourself and only carry three texture channels. After adding a texture channel shader, the problem was perfectly solved.

postscript:

Although the problem has been solved this time, there are still some questions. What if we have to use the standard shader that comes with Unity? What to do?

It stands to reason that Unity's standard shader is very commonly used. There should be a lot of information about this on the Internet, but I haven't found it despite all my efforts, or there are other places that need to be set up. It's not clear yet. Has anyone encountered this problem? Welcome to leave a message in the comment area for discussion.