Camera NullReferenceException

I have the following script attached to my camera.

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class ScaleWidthCamera : MonoBehaviour 
{
	public float targetWidth = 1920;
	public float FOV = 42f;

	void OnGUI()
	{
		float height = (targetWidth / Screen.width) * Screen.height;

		camera.orthographicSize = (height / FOV) / 2f;
	}
}

Sometimes when I’m in the editor I get a NullreferenceException error on the camera. Along with !CompareApproximately (det, 1.0F, .005F)

This makes absolutely no sense since camera clearly exists and I only get this error once. When I run the game this script works just fine (It is used by a slider that adjusts the FOV value).

Before you say anything about using OnGUI(), I did that because if the FOV is changed during Update() or FixedUpdate(), it causes a stuttering movement as the FOV is changed.

Ok I just fixed this myself. Apparently the editor was trying to change the FOV value before all the references were setup in my prefabs. Making FOV static got rid of the errors.