Advanced Mesh Rendering give insane index value

Hey I found weird stuff that my brain can’t explain why this happens.

I’m learning mesh rendering and using catlikecoding website for tutorials. (Square Grid) I finished section #1.6. When I did press run I got this error:

ArgumentException: Index buffer element #0 (value 1953066581) is out of bounds; mesh only has 4 vertices.

Any clue why do I get this insane index value?

I did check the code many many times, but can’t find anything.

EDIT:
github link is here:
All files in that folder including subfolders
https://github.com/jTuisk/TKO_3123/tree/main/Survival Game/Assets/Src/Scripts/Procedural Meshes

and this script goes to object.
https://github.com/jTuisk/TKO_3123/blob/main/Survival Game/Assets/Src/Scripts/Misc/ProceduralMesh.cs

Square Grid fixed link, since that one had some junk on the end

You should show the code you’re currently trying to run. We cannot give you much advice without seeing it.

There is a lot of different files, that why I did not post it.
github link is here:
All files in that folder including subfolders
https://github.com/jTuisk/TKO_3123/tree/main/Survival Game/Assets/Src/Scripts/Procedural Meshes

and this script goes to object.
https://github.com/jTuisk/TKO_3123/blob/main/Survival Game/Assets/Src/Scripts/Misc/ProceduralMesh.cs

Edit: Should I just upload scripts to orginal post or?

I had the same problem,but it worked fine after I was rewriting(but I didn’t change it)the variable name of SingleStream,I think this is a problem or a error with the code editor(VS).

You don’t need to post code, you need to debug code.

Just because this code came from a tutorial, it still might need debugging for any number of reasons.

In any case, staring at code is almost never a useful approach to fixing it.

And that is why we have debugging.

First, just some information about this specific bug:

Here are some notes on IndexOutOfRangeException and ArgumentOutOfRangeException:

Steps to success:

  • find which collection it is and what line of code accesses it <— (critical first step!)
  • find out why it has fewer items than you expect
  • fix whatever logic is making the indexing value exceed the collection size

Remember also:

  • a collection with ZERO elements cannot be indexed at all: it is empty
  • you might have more than one instance of this script in your scene/prefab
  • the collection may be used in more than one location in the code
  • indices start at ZERO (0) and go to the count / length minus 1.

This means with three (3) elements in your collection, they are numbered 0, 1, and 2 only.

Finally, here’s how to begin your debugging adventures:

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

ohno,it happened again,but it worked fine after I delete the part of Burst

I know why it went wrong now, this is problem of Brust which named " Memory aliasing",and this the official document about it
https://docs.unity3d.com/Packages/com.unity.burst@1.3/manual/index.html#synchronous-compilation
You can solve it based on the following code,add [NoAlias] before the Native arr;

        [NativeDisableContainerSafetyRestriction]
        [NoAlias]
        NativeArray<Stream0> stream0;

        [NativeDisableContainerSafetyRestriction]
        [NoAlias]
        NativeArray<TriangleUInt16> triangles;