SplatMap error

I use some code to procedurally paint the terrain. But for some reason the splatmap variable sometimes becomes smaller or I atleast get a error with the current iteration being out of range.
Error:

IndexOutOfRangeException: Array index is out of range.
(wrapper managed-to-managed) object:ElementAddr (object,int,int,int)
PT+$UpdateTile$72+$.MoveNext () (at Assets/Scripts/PT.js:272)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
$:MoveNext() (at Assets/Scripts/PT.js:98)
UnityEngine.MonoBehaviour:StartCoroutine_Auto(IEnumerator)
StartMenu:SpawnPlayer() (at Assets/Scripts/StartMenu.js:716)
StartMenu:OnGUI() (at Assets/Scripts/StartMenu.js:273)

and for some reason when doing a check like the code below, it is the first line that returns the error, why doesn’t that line prevent the error from occuring, since if it is out of range, it should be null right?

if (map[z,x,0] != null) { //For some reason it is this line that gives a null
	map[z,x,0] = 1;
}

If your map is, say, a 2x2x2 array (i.e. map[2,2,2]) and you try to access an index outside that range (i.e. map[4,5,6]), you’ll get an “array index is out of range” error as you have done.

Your if map[z,x,0] != null check doesn’t prevent this error - that tests whether a value at a given position in the array is null, but your array doesn’t even contain that many elements.

Please paste the code where you declare map, and where you assign the values z and x.