Fatal error after loading image and drawing texture

Hey guys, I’m trying to implement a simple script to display images. The images load fine and are drawn to the screen but after about 15 seconds a fatal error occurs and Unity crashes.
Here’s my code stripped down…

void Start () {
		
		xu  = Screen.width;
		yu  = Screen.height;
	
		www = new WWW(@"file://D:\Slides\Assets\Final Renders\IM_00.jpg");	
	}
	
	void OnGUI() {		
		GUI.DrawTexture(new Rect(0,0,xu/2,yu), www.texture, ScaleMode.ScaleToFit);	
	}

Here is the error I’m getting…

When the ‘GUI.DrawTexture(new Rect(0,0,xu/2,yu), www.texture, ScaleMode.ScaleToFit);’ line is commented out no error occurs.
The image is a JPEG and roughly 140KB. If anyone can point me in the right direction as to what I’m doing wrong it will be greatly appreciated! Cheers

I think it’s probably that you’re trying to render the texture before it’s actually finished downloading (the WWW class will start the download immediately, but it still takes time).

Try changing your OnGUI to something like…

void OnGUI() 
{
    if (www.isDone)
    {
       GUI.DrawTexture(new Rect(0,0,xu/2,yu), www.texture, ScaleMode.ScaleToFit);
    }
}