Simple Account System (WWW works locally, freezes and crashes flash in web player)

Im assuming this is happening because of the sandbox. However, Im a little lost.

It works locally (in the IDE), the url is correct, the logic is correct etc. The server returns a response, locally I get a response. The json parser works correctly. It also works if I build to a Windows EXE. However, in a webplayer - it does not work (im guessing there is some security setting im missing or something).

A crossdomain policy exists on the localhost server.

I am using the webplayer locally, Ive even tried publishing to the same server as the requests are going to.

Example: http://localhost:85/gamemaster <<serves my requests
Example: http://localhost:85/logintest <<has the webplayer with the app

Here is my code.
Im not sure why it freezes and crashes the browser.

public bool Login(string email,string password){
	
		errorMessage="";
		string reqUrl=baseUrl+"index.php?r=user/login";
		reqUrl+="&email="+email;
		reqUrl+="&password="+password;
		
		//WWWForm form=new WWWForm();
		//form.AddField ("email",email);
		//form.AddField ("password",password);
		
	
		WWW www=new WWW(reqUrl);
		while (!www.isDone){ LoginCor (www); } //wait for data to load
		
		//done
		Debug.Log ("done");
		if (www.error==null){
			//todo: move this to the proper code block after success has been tested
			//user=User.CreateInstance<User>();
			//user.email=email;
		
		
			string jsonString=www.text;
	
			Dictionary<string,object> dict = Json.Deserialize(jsonString) as Dictionary<string,object>;
			if ((bool)dict["error"]){
				errorMessage=dict["message"].ToString();
			}else{
				return true;	
			}
		}else{
			Debug.Log (www.error);
			www.Dispose();
		}
		return false;
	}
	
	IEnumerator LoginCor(WWW www){	
		yield return www;	
	}

I would appreciate any insight. Thank you :slight_smile:

anyone got any insight?

i have the same problem too, may be we have no choice but to test it online :frowning:

I think it has to do with this. In fact, the documentation on WWW.isDone specifically says you can’t do it that way in a Webplayer, and that you shouldn’t do it at all really.

Try something like this:

void SomeOtherCode() {
	StartCoroutine(Login(email, pass));
}

public IEnumerator Login(string email,string password){
	
	errorMessage="";
	string reqUrl=baseUrl+"index.php?r=user/login";
	reqUrl+="&email="+email;
	reqUrl+="&password="+password;
	
	WWW www=new WWW(reqUrl);
	yield return www;
	
	//done
	Debug.Log ("done");
	if (www.error==null){
		string jsonString=www.text;

		Dictionary<string,object> dict = Json.Deserialize(jsonString) as Dictionary<string,object>;
		if ((bool)dict["error"]){
			LoginDone(false, errorMessage=dict["message"].ToString());
		}else{
			//todo: move this to the proper code block after success has been tested
			//user=User.CreateInstance<User>();
			//user.email=email;
			LoginDone(true, "Success!");
		}
	}else{
		LoginDone(false, www.error);
	}
	www.Dispose();
}

void LoginDone(bool success, string msg) {
	if (success) {
		Debug.Log(msg);
	}
	else {
		Debug.LogError("Login failed. Error: " + msg);
	}
}

It looks like your current code is just calling the coroutine over and over, and it happens to work when you’re on a local machine because it loads instantly and is therefore true the very first time you called it. Doing it this new way means getting that bool out of your login function is a little trickier, but not impossible. I made a guess as to how you might be using it, but you can probably adjust it to fit what you were doing.