- Home /
Question by
Yamashi · Jul 22, 2014 at 03:05 PM ·
crash logterrain bug
Player crash when adding a terrain in Update
Hi,
I am trying to build a procedural terrain on the fly, it works fine in the editor but as soon as I build a standalone player it just crashes when I add the terrain. I have found that disabling the prototypes fixed the crash but this is not a satisfying solution as I need those.
The following function is called in Update().
void AddTerrain(ushort aX, ushort aY, float[,] aHeightMap)
{
TerrainData terrainData = new TerrainData ();
terrainData.heightmapResolution = m_heightMapSize;
terrainData.SetHeights (0, 0, aHeightMap);
terrainData.size = new Vector3 (m_terrainSize, m_terrainHeight, m_terrainSize);
//terrainData.splatPrototypes = m_splatPrototypes;
//terrainData.treePrototypes = m_treeProtoTypes;
//terrainData.detailPrototypes = m_detailProtoTypes;
FillAlphaMap (terrainData);
uint terrainKey = MakeKey (aX, aY);
m_terrainMap.Add (terrainKey, Terrain.CreateTerrainGameObject (terrainData).GetComponent<Terrain> ());
m_terrainMap [terrainKey].transform.position = new Vector3 (m_terrainSize * aX + m_offset.x, 0, m_terrainSize * aY + m_offset.y);
m_terrainMap [terrainKey].heightmapPixelError = m_pixelMapError;
m_terrainMap [terrainKey].basemapDistance = m_baseMapDist;
//disable this for better frame rate
m_terrainMap [terrainKey].castShadows = false;
FillTreeInstances (m_terrainMap [terrainKey], aX, aY);
FillDetailMap (m_terrainMap [terrainKey], aX, aY);
}
If someone can help I would greatly appreciate it.
Thanks
Comment