Unity crashes on play when generating texture.

Hi! Recently I have been playing around with graphics programming in unity and while attempting to create a c# script to generate a LUT unity crashes everytime I hit play ONLY when the script is enabled. I’m sure its down to dodgy programming as my c# is a bit meh. Heres the code:

using UnityEngine;
using System.Collections;


public class GenerateBeckmann : MonoBehaviour {
	public int size = 64;
	private Material currentMaterial;
	public Texture2D generatedTex;
	
	float PHBeckmann(float ndoth,float m){
		float alpha = Mathf.Acos (ndoth);
		float ta = Mathf.Tan(alpha);
		float val = 1f/(m*m*Mathf.Pow(ndoth,4f)) * Mathf.Exp(-(ta * ta) / (m * m));
		return val;
	}
	private Texture2D Beckmann(){
		Texture2D beckmann = new Texture2D(size,size,TextureFormat.ARGB32,false);
		for(int i=0;i<size;i++){
			for(int j = 0;j<size;i++){
				float val = 0.5f * Mathf.Pow(PHBeckmann(i/(float) size, j/(float)size), 0.1f);
				beckmann.SetPixel(j, i, new Color(val,val,val,val));
			}
		}
		beckmann.Apply ();
		return beckmann;
	}
	
	// Use this for initialization
	void Start () {
		if(!currentMaterial){
			currentMaterial = transform.renderer.sharedMaterial;
			if(!currentMaterial){
				Debug.LogWarning ("Cannot find a material on: "+transform.name);
			}
			
		}
		if(currentMaterial)
		{
			generatedTex = Beckmann ();
			currentMaterial.SetTexture ("_MainTex",generatedTex);
		}
	
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

This is strange…The script runs perfectly now after using unity 2 days later…weird.