Application.Tick fro 10 minutes after terrainData.SetHeights()

Hi. After running this code in the editor

    private void ApplyStencilToTerrain(Terrain terrain, Color[] stencilPixels, int stencilWidth, int stencilHeight, Vector3 minPos, Vector3 totalSize)
    {
        TerrainData terrainData = terrain.terrainData;
        int resolution = terrainData.heightmapResolution;
        float[,] heights = terrainData.GetHeights(0, 0, resolution, resolution);

        Vector3 terrainPos = terrain.transform.position;
        Vector3 terrainSize = terrainData.size;
        float maxHeightNormalized = maxHeight / terrainSize.y;

        for (int y = 0; y < resolution; y++)
        {
            for (int x = 0; x < resolution; x++)
            {
                float normalizedX = (terrainPos.x - minPos.x + (float)x / resolution * terrainSize.x) / totalSize.x;
                float normalizedY = (terrainPos.z - minPos.z + (float)y / resolution * terrainSize.z) / totalSize.z;

                int stencilX = Mathf.FloorToInt(normalizedX * (stencilWidth - 1));
                int stencilY = Mathf.FloorToInt(normalizedY * (stencilHeight - 1));
                Color stencilColor = stencilPixels[stencilY * stencilWidth + stencilX];

                heights[y, x] = (stencilColor.r > 0.5f) ? maxHeight : 0f;
            }
        }

        terrainData.SetHeights(0, 0, heights);
    }

I immediately get the editor wait dialog Application.Tick() for about 10 minutes and then it goes away. I’ve restarted editor, am not debugging and have also tried restarting PC.

I should mention the code itself completes in just a second or two.

Is there any way to determine the cause for this dialog. I assume its something in my code but I can’t see it.

Thanks

I assume it should be visible in Unity’s Profiler. Here is how I would try to find out what is causing it:

  1. Open Profiler from Window > Analysis > Profiler Unity - Manual: Profiler overview
  2. Switch from “Play Mode” to “Edit Mode” in Profiler toolbar
  3. Press “Record” button in Profiler toolbar
  4. Execute your editor code
  5. Press “Record” button in Profiler toolbar again to stop profiling. Here you need to be fast to stop right after those 10 minutes freeze, because you only have a few seconds before the profiler data moved out of view.
  6. Select expensive sample in Profiler “CPU Usage” graph
  7. Switch Profiler panel from “Timeline” to “Hierarchy”
  8. Drill down most expensive things in Hierarchy panel to find out where those 10 minutes come from

Hey mate, thanks for going to so much trouble and providing those details. I’ll check it out tomorrow and see how it goes.

Cheers