WebGL: RangeError: invalid array length

We’ve been working on getting a successful WebGL build for quite a while now with no success.

Having tried all the various configuration/build settings, I now have a build that at least no longer produces the “out of memory” error. Now I am receiving the very informative “invalid array length” error.

This is using the latest Firefox (v38.0.1) so I dont believe it is similar to the known Chrome memory issue of “invalid typed array”.

Is there any way to get more information on what this error is referring to?

Thanks!

Is there any further info in the JS console?
Could you post a link to that build ?

I’m getting the same error. Running “Fastest (slowest build)” mode. Firefox console output:

[16:11:00.222] syntax error @ file:///C:/Users/denisk/plastitools-webgl-out/Release/plastitools-webgl-out.js:1
[16:11:02.601] optimizing out Math.fround calls

[16:11:16.865] increasing TOTAL_MEMORY to 2164260864 to be more reasonable
[16:11:16.865] Invoking error handler due to
RangeError: invalid array length

[16:11:25.326] RangeError: invalid array length @ blob:21e5ba18-d1bd-4a67-b490-05879399da55:1

Also, during the build the following errors show up:

IOException: Sharing violation on path C:\Program Files\Unity\Editor\Data\PlaybackEngines\webglsupport\BuildTools\WebGLTemplates\Minimal\index.html" or "C:\Users\denisk\plastitools-webgl-out\index.html
System.IO.File.Copy (System.String sourceFileName, System.String destFileName, Boolean overwrite) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:124)
UnityEditor.FileUtil.UnityFileCopy (System.String from, System.String to, Boolean overwrite) (at C:/buildslave/unity/build/Editor/Mono/FileUtil.cs:207)
UnityEditor.FileUtil.CopyDirectoryFiltered (System.String source, System.String target, Boolean overwrite, System.Func`2 includeCallback, Boolean recursive) (at C:/buildslave/unity/build/Editor/Mono/FileUtil.cs:142)
UnityEditor.FileUtil.CopyDirectoryFiltered (System.String source, System.String target, Boolean overwrite, System.String regExExcludeFilter, Boolean recursive) (at C:/buildslave/unity/build/Editor/Mono/FileUtil.cs:121)
UnityEditor.FileUtil.CopyDirectoryRecursiveFiltered (System.String source, System.String target, Boolean overwrite, System.String regExExcludeFilter) (at C:/buildslave/unity/build/Editor/Mono/FileUtil.cs:102)
UnityEditor.FileUtil.CopyDirectoryRecursiveForPostprocess (System.String source, System.String target, Boolean overwrite) (at C:/buildslave/unity/build/Editor/Mono/FileUtil.cs:97)
UnityEditor.WebGL.WebGlBuildPostprocessor.CopyFinalFilesToInstallPath (BuildPostProcessArgs args)
UnityEditor.WebGL.WebGlBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
UnityEditor.HostView:OnGUI()

Error building Player: IOException: Sharing violation on path C:\Program Files\Unity\Editor\Data\PlaybackEngines\webglsupport\BuildTools\WebGLTemplates\Minimal\index.html" or "C:\Users\denisk\plastitools-webgl-out\index.html

@liortal ,

Not much else in the console; that’s the strange part. I did get these 3 warnings immediately prior to the RangeError:

…but those didnt look out of the ordinary.

Unfortunately, this is not a public-facing project at the moment as Im doing all testing locally.

I am not getting the IOExceptions that Denis reported.

This is probably because you are setting an invalid value for WebGL memory size. Values large then 2047 or smaller then 0 result in negative 32-bit signed integer sizes of bytes, and cause an “invalid array length” error.

Unity 5.1 will make sure you can only supply valid values in this field.

1 Like

Jonas,

That would be the issue! I was setting the memory size to 2048 in hopes of avoiding the ‘out of memory’ issue in Firefox.

Thanks very much for clarifying.

Unfortunately, now Im back to the drawing board on trying to determine what is eating up so much memory space in this build. Large functions? A couple MB of textures? More trial and error of stripping stuff away, I guess…:frowning:

Yep, just FYI i was getting issues with the Range Error. Memory was set to 1024, changed to 512 and its all good.

I m getting this (apparently same) error with Unity 5.3.

Specifics:
memory size in Player Settings: 1024
memory size in var Module.TOTAL_MEMORY: 1073741824
problem shows up on Chrome, Opera, but NOT Firefox (all on Windows 7, 64bit)
fastest build with stripping activated

js-console wont reveal much detail:
optimizing out Math.fround calls
Invoking error handler due to Uncaught RangeError: Invalid typed array length
Uncaught RangeError: Invalid typed array length

BR,

Why do you need 1GB of memory for your content ?

I assume Chrome and Opera are running out of memory because they are 32bit, while Firefox is 64 bit. Is that right ?

having problem in unity webGl build ,

when i build with less then 2047 mb . it show error Alert memory is less
and when i use 2047 mb momery , it simply show this Alert
“An error occured running the Unity content on this page. See your browser’s JavaScript console for more info. The error was:
RangeError: invalid array length”

Because anti aliasing looks like shit even with 1000mb memory…at 512mb it’s laughable…

I’m getting this same error RangeError: Invalid Typed Array Length with a setting of 1024mb…but 1000 works, trying to figure out what the highest I can set without crashing is, and it’s nowhere near 2047mb…

I’m using Unity 5.3, the project has 17mb of textures and 30mb of meshes uncompressed in the build log, actual size is 40mb total for the build, client is complaining of anti aliasing at current settings so looking for options…

Have you looked at it with the memory profiler as well ?

Strange, that usually means the browser does not have enough memory to allocate the Unity Heap and to fix it you should reduce it.

Have you profiled it ?

are you using your own post-processing AA ?

1 Like

it alert at start , so i can not profile it ,

its production time for this app , is there any thing that could help he…?

Have you tried with a 64-bit browser ?

can you look at the size of your uncompressed .data and .js files ? (take the build.datagz/jsgz, rename them to .gz and upzip them)

No, the 8x AA in the quality settings…

I’ve noticed:
If I limit the webGL memory to 512mb, I get 0 AA effect in builds while it looks great in the editor.

If I raise the memory allowance to 1000mb, builds show about 50% of the AA that the editor shows, I haven’t been able to get a build to not crash at 1023mb or higher. From what I’ve read custom AA doesn’t work in webgl…do you know of one that does?

Are you saying to use the profiler in Unity, or is there one in the browser? (attached image from unity’s profiler)

edit:: I’m looking through the profile for the browser console (F12) and am not quite sure what I’m supposed to be looking for…? (attached image of browser profiler as well)


i m using 64 bit browser ,
after some experiments i came to konw , one of my texture max size was grater then 4096 , when i correct it , starts working well,

but after it i start facing an other problem , unity project does not loads in browse , it just stuck …

OK, then you are using the builtin webgl anti-aliasing. So, it works if it’s supported by both browser and graphics card.
The type of AA you select (2, 4 or 8) is not actually taken into account since it depends on the browser (that’s just the way webgl works).
to know whether AA is actually enabled at runtime, try to type this in the browser console:

canvas = document.getElementById("canvas");
gl = canvas.getContext('webgl');
gl.getContextAttributes().antialias;

I mean to profile your webgl build using the Unity profiler, using the Autoconnect Profiler flag.

1 Like

Hi can you help me? I have error after running WebGL application in my browsers:



2559222--178188--9027128[1].png
2559222--178189--9025080[1].png