Problem with this Script ... crash iPhone

Hello,
well back @ work i get some trouble with this script…
I want to load a Webpage into a Texture.
First i call the webpage … then i translate it to a .jpg
last i load it into a texture…
sometime it works somtime it crashes… ???
so if you have a idea what going wrong plz tell it :slight_smile:
thank you

using UnityEngine;
using System.Collections;

public class JLoadPage : MonoBehaviour {

	public Material pageMaterial;
	public Material pageMaterialerror;
	bool loading = true;
	float nextUpdate;
	public float reloadtime = 15.0f;
	// Use this for initialization
	void Start () {
		StartCoroutine(MyLoadPage("http://en.wikipedia.org/wiki/Special:Random"));
	}
	
	IEnumerator MyLoadPage(string url) {
		WWW www = new WWW("http://www.i-dvd.net/unitycallweb.php?url=" + WWW.EscapeURL(url));
		while (![url]www.isDone[/url]) {
	        yield return www;
		}
		if ([url]www.error[/url] == null) {
			string str = [url]www.data;[/url]
			www = new WWW(str);
			while (![url]www.isDone[/url]) {
	        	yield return www;
			}
			if ([url]www.error[/url] == null) {
				pageMaterial.mainTexture = [url]www.texture;[/url] 
			}
			else {
//				Debug.Log("error2 = '" + [url]www.error[/url] + "'");
				pageMaterial.mainTexture = pageMaterialerror.mainTexture; 
			}
		}
		else {
//			Debug.Log("error = '" + [url]www.error[/url] + "'");
			pageMaterial.mainTexture = pageMaterialerror.mainTexture;
		}
		nextUpdate = Time.time + reloadtime;
		loading = false;
    }
	
	
	// Update is called once per frame
	void FixedUpdate () {
		if ((loading == false)  (Time.time > nextUpdate)) {
			StartCoroutine(MyLoadPage("http://en.wikipedia.org/wiki/Special:Random"));
			loading = true;			
		}
	}
}

Hello! :slight_smile:

how does it crashes?, does it gets Unity to freeze? or does the page not get loaded?, do you get errors?

it doesn’t crash Unity but the iPhone App crash after 2-6 load attempts…
In Unity itself it works rock solid…
thxx
kerstin :sweat_smile:

Ok,This is a tought,

Maybe sometimes you are not getting response from the web from your iPhone, which leads me to think that you are getting a null value for the texture and that makes the app crash.

That doesnt mean that the Unity Editor crashes because it maybe is able to handle that null reference.

again, its just a tought, but maybe it can help you!
:wink:

Hey thaxxx for the Tip !
Do you also know what i can do ?
I have no idea…
thank you

kerstin :sweat_smile: