Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IndexAutoFrangeException仅适用于Mac OS X单机版_C#_Macos_Unity3d - Fatal编程技术网

C# IndexAutoFrangeException仅适用于Mac OS X单机版

C# IndexAutoFrangeException仅适用于Mac OS X单机版,c#,macos,unity3d,C#,Macos,Unity3d,我在游戏中遇到了一个IndexOutOfRange异常,但只在Mac OS X上的独立版本中出现。它在Windows和OSX上的Unity编辑器中运行良好,在Windows和Android上作为独立版本运行良好。然而,在OSX上,我得到了以下异常: IndexOutOfRangeException: Array index is out of range. at WorldController.InstantiateChunk (Vector2i pos, .MeshBuildInfo[]

我在游戏中遇到了一个IndexOutOfRange异常,但只在Mac OS X上的独立版本中出现。它在Windows和OSX上的Unity编辑器中运行良好,在Windows和Android上作为独立版本运行良好。然而,在OSX上,我得到了以下异常:

IndexOutOfRangeException: Array index is out of range.
  at WorldController.InstantiateChunk (Vector2i pos, .MeshBuildInfo[] meshes) [0x00072] in /Users/sargunster/Code/Unity Projects/block-game/Assets/Scripts/World/Objects/WorldController.cs:226 
  at WorldController.FixedUpdate () [0x00060] in /Users/sargunster/Code/Unity Projects/block-game/Assets/Scripts/World/Objects/WorldController.cs:79 
以下是相关功能:

void InstantiateChunk(Vector2i pos, MeshBuildInfo[] meshes)
{
    float worldX = pos.x * World.CHUNK_SIZE - .5f;
    float worldZ = pos.z * World.CHUNK_SIZE - .5f;

    // for each chunk in the column
    for (int y = 0; y < World.WORLD_HEIGHT; y++)
    {
        float worldY = y * World.CHUNK_SIZE - .5f;

        // instantiate the chunk
        Vector3 position = new Vector3(worldX, worldY, worldZ);
        string name = System.String.Format(" Chunk at ({0}, {1}, {2})", pos.x, y, pos.z);

        // THIS IS WHERE IT HAPPENED
        ChunkRenderer opaque = MakeChunk(position, "Opaque" + name, meshes[y].opaque, opaqueMaterial);

        ChunkRenderer transparent = MakeChunk(position, "Transparent" + name, meshes[y].transparent, transparentMaterial);
        Vector3i chunkPos = new Vector3i(pos.x, y, pos.z);
        opaqueInstances.Add(chunkPos, opaque);
        transparentInstances.Add(chunkPos, transparent);
    }
}
因此,我进入调试器查看异常发生时变量的确切值。调试器输出:

> meshes
Evaluation failed.
> 2+2
4
> meshes.Length
Evaluation failed.
> y
0
> position
{(-7168.5, -0.5, 4079.5)}
索引为0,我可以很好地计算表达式。。。除了不起作用的阵列。我无法得到它的长度或它的值

我不知道如何解决这个问题。“评估失败”是什么意思?索引怎么可能超出范围?为什么这只发生在OSX上?我怎么修理它


World.World\u HEIGHT
是一个值为16的常数

经过几天对这个问题的沮丧,我终于(某种程度上)解决了它。只有当游戏构建为x86_64或通用时,才会发生这种情况。将架构设置更改为x86解决了这个问题。一定是Unity错误。

WorldController.cs中的第226行是哪一行?虽然是,但可能是网格。长度无法计算,因为它是空的…?我在发布的代码中用注释标记了这一行。嗯,网格也无法计算。如果网格不是空的(您检查了吗?)然后下一步是将mesh.Length添加到一个变量中,以便在调试器中查看它。我报告了该错误,并收到了一封电子邮件,确认它确实是一个Unity错误,将在下一个版本中修复。
> meshes
Evaluation failed.
> 2+2
4
> meshes.Length
Evaluation failed.
> y
0
> position
{(-7168.5, -0.5, 4079.5)}