title: Why does Unity get stuck on Application.EnterPlayMode?
body: <p>I'm trying to create procedural terrain generator using perlin noise and marching cubes in unity. It was working until I switched from creating a height map to making it into a 3d array. Then, whenever I clicked on play, unity opened a dialog box with Application.EnterPlayMode written which would not go away and never entered play mode. Everything stops responding when it happens and they only way to stop it is to kill it in task manager.</p>
  <p><strong>The script in question is below:</strong></p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Noise : MonoBehaviour
  {
      //Determines whether to show debug values
      public bool debug = false;
  
      //Determines flatness of the terrain
      public float noiseScale = 0.5f;
  
      //Type of perlin noise to use
      public enum PerlinNoise {
          twoD,
          threeD
      };
      public PerlinNoise perlinNoiseDimension = PerlinNoise.twoD;
  
      //To return noise data after all calculations
      public float[,,] getTerrainData(int x, int y, int z)
      {
          float[,,] terrainData = new float[x, y, z];
  
          if(perlinNoiseDimension == PerlinNoise.twoD)
          {
              terrainData = PerlinNoise2D(x, y, z, noiseScale);
          }
          return terrainData;
      }
  
      //Determine noise values using 2D Perlin noise
      private float[,,] PerlinNoise2D(int x, int y, int z, float noiseScale)
      {
          float[,,] voxelHeights = new float[x, y, z];
  
          if (debug)
          {
              Debug.Log(&quot;Heightmap&quot;);
          }
  
          //Origin points to sample from
          float xOrg = Random.Range(0.0f, 0.9999999f);
          float yOrg = Random.Range(0.0f, 0.9999999f);
  
          for (int currentx = 0; currentx &lt; x; currentx++)
          {
              for (int currenty = 0; currenty &lt; y; currenty++)
              {
                  //Convert Values to Fractions
                  float xCoord = (float)currentx / (x * noiseScale) + xOrg;
                  float yCoord = (float)currenty / (y * noiseScale) + yOrg;
  
                  float height = Mathf.PerlinNoise(xCoord, yCoord) * z;
  
                  for(int currentz = 0; currentz &lt;= height; z++)
                  {
                      voxelHeights[currentx, currenty, currentz] = 1;
                  }
  
                  if (debug)
                  {
                      Debug.Log(&quot;Height = &quot; + height + &quot;, X = &quot; + currentx + &quot;, Y = &quot; + currenty + &quot;, X Coord = &quot; + xCoord + &quot;, Y Coord = &quot; + yCoord);
                  }
              }
  
          }
          return voxelHeights;
      }
  }
  </code></pre>
  <p><strong>An image of what it shows is below:</strong></p>
  <p><a href="https://i.stack.imgur.com/JvEKP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JvEKP.png" alt="The error" /></a></p>