Search Unity

Noise and Grain - IndexOutOfRangeException: Array index is out of range.

Discussion in 'Image Effects' started by JBT27, Aug 11, 2016.

  1. JBT27

    JBT27

    Joined:
    Jul 13, 2016
    Posts:
    197
    I've been getting this on the previous build and now on the current one, using Windows Unity 5.4.0f3.

    The project uses Helios to record frames. Although the game view displays, output frames are black with this error.

    I've spoken with the dev of Helios who says this is not a Helios problem, and that the error of course is entirely from the noise and grain script. Would appreciate any ideas.

    Thanks.
     

    Attached Files:

  2. Moj

    Moj

    Joined:
    Jun 7, 2012
    Posts:
    2
    I get the same thing if I run the game view at 1024x768. Index out of range in NoiseAndGrain.cs (Unity Windows 5.4.2f2)
    The problem seems to be 4:3 resolutions.

    (Filename: Assets/Standard Assets/Effects/ImageEffects/Scripts/NoiseAndGrain.cs Line: 185)

    IndexOutOfRangeException: Array index is out of range.
    at UnityStandardAssets.ImageEffects.NoiseAndGrain.BuildMesh (UnityEngine.Mesh mesh, UnityEngine.RenderTexture source, UnityEngine.Texture2D noise) [0x000c0] in D:\repos\CosmosTactics\CosmosTactics\Assets\Standard Assets\Effects\ImageEffects\Scripts\NoiseAndGrain.cs:185
    at UnityStandardAssets.ImageEffects.NoiseAndGrain.DrawNoiseQuadGrid (UnityEngine.RenderTexture source, UnityEngine.RenderTexture dest, UnityEngine.Material fxMaterial, UnityEngine.Texture2D noise, UnityEngine.Mesh mesh, Int32 passNr) [0x00025] in D:\repos\CosmosTactics\CosmosTactics\Assets\Standard Assets\Effects\ImageEffects\Scripts\NoiseAndGrain.cs:141
    at UnityStandardAssets.ImageEffects.NoiseAndGrain.OnRenderImage (UnityEngine.RenderTexture source, UnityEngine.RenderTexture destination) [0x00187] in D:\repos\CosmosTactics\CosmosTactics\Assets\Standard Assets\Effects\ImageEffects\Scripts\NoiseAndGrain.cs:93
    UnityEditor.EditorGUIUtility:INTERNAL_CALL_RenderGameViewCamerasInternal(RenderTexture, Int32, Rect&, Vector2&, Boolean)
    UnityEditor.EditorGUIUtility:RenderGameViewCamerasInternal(RenderTexture, Int32, Rect, Vector2, Boolean) (at C:\buildslave\unity\build\artifacts\generated\common\editor\EditorGUIUtilityBindings.gen.cs:606)
    UnityEditor.GameView:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\GameView\GameView.cs:680)
    System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
    System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    System.Reflection.MethodBase:Invoke(Object, Object[]) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.HostView:Invoke(String, Object) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:187)
    UnityEditor.HostView:Invoke(String) (at C:\buildslave\unity\build\Editor\Mono\HostView.cs:180)
    UnityEditor.DockArea:OnGUI() (at C:\buildslave\unity\build\Editor\Mono\GUI\DockArea.cs:355)
     
  3. JBT27

    JBT27

    Joined:
    Jul 13, 2016
    Posts:
    197
    I'm getting the error on 16:9 as well. Still no change on 5.4.1p4.
     
  4. seobyeongky

    seobyeongky

    Joined:
    Sep 29, 2015
    Posts:
    11
    It seems an algorithm of the shader couldn't deal with floating-point calculation correctly.
    So I modified the script.

    Code (CSharp):
    1.                 float x1 = 0;
    2.                 float y1 = 0;
    3.                 for (int w = 0; w < meshWidth; w++, x1 += stepSizeX)
    4.                 {
    5.                     y1 = 0;
    6.  
    7.                     for (int h = 0; h < meshHeight; h++, y1 += stepSizeY)
    8.                     {