Unity unexplicably freezes on a very simple procedure

I’m working on the very beginnings of a random level generator. I’m running this code:

using UnityEngine;
using System.Collections;

public class Generator : MonoBehaviour {

	public GameObject rock;

	// Use this for initialization
	void Start () {

		Desert (10, 10, 2, 2);

	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void Desert(int startx, int startz, int width, int length) {

		Vector3 pos;

		for (int i = startx; i < width + startx; i++) {
			for (int j = startz; i < length + startz; j++) {

				pos = new Vector3(i, 0, j);
				Instantiate(rock, pos, Quaternion.identity);

			}
		}

	}
}

All this does is generate a 2 x 2 square using a prefab cube of (1, 1, 1) with a texture on it.

Running this very simple code cause my Unity to freeze and pretty much die.

My computer is not a beast but it’s been through much, much worse.

Can anyone explain why this would freeze?

1 Answer

1

On line 25 you have used the variable “i” in your check instead of “j”. This would cause the loop to never finish as the i variable never changes in that loop.

This is the correct answer. :)

totally missed that :D I guess that's why i never use similar letters for "for-variables". either "n", "i", "k" or if it's related to a certain axis "x", "y", "z" Anyways +1