yield return request never returns

Hi,

I’m having problems with yield: “yield return request;” never returns on Android device of my customer. I looked for existing answer, but couldn’t find any useful hints.

using UnityEngine;
using System.Collections;

public class TestConnection : MonoBehaviour {

	// Use this for initialization
	void Start () 
	{
		StartCoroutine(Test());
	}
	
	IEnumerator Test()
	{
		string tag = "Test";
		Debug.Log("Test connection: " + tag);
		
		string url = "http://search.twitter.com/search.atom?lang=en&q=%23" + tag;
   		WWW request = new WWW(url);
		
		Debug.Log("Created request");
    
    	// Wait for download to complete
		yield return request;
		
		Debug.Log("Done request. Error: " + (request.error != null ? request.error : "NoError"));
		Debug.Log("request.text: " + request.text);
    
		GetComponent<Text2D>().text = request.text.Substring(0, 50);
		
		Debug.Log("Set text");
	}
}

I just prints: “Test connection: Tag” and “Created request” and then just sits there.

Any ideas?

@Bovine: certainly "request" is being used, that's what "yield return request" is doing, as well as the actual results, namely request.text. Yield return null just waits a frame, which isn't useful at all in this case.

(looks like UnityAnswers ate your formatting... please reformat...)

It's weird that format breakage happens sometimes. I just edited, added a blank line and saved. Odd.

It's conceivable that on your Android device there is something wrong with networking (so the request never completes). Does it all work fine in the editor?

It works fine in the editor. The Android device can open same link in a browser.

2 Answers

2

I believe that for proper debugging you could try using a coroutine, adding a timer inside it and another timer in the caller function, to verify if the routine’s actually running or has frozen for whatever reason, sending both timers to log.

Sorry, could you explain what you mean by "adding timer inside coroutine"? I can't add anything to WWW class, my coroutines run fine... The rest of the code runs fine - it's just coroutine that freezes.

Maybe the suggestion is to see if replacing the yield return WaitForSeconds(5) will continue or whether that blocks as well - you could yield return null to confirm this. At least you know the issue is with the WWW object and coroutines generally then.

I am pretty sure this is a timing issue. by "try using a coroutine" i meant move your string tag = "Test"; Debug.Log("Test connection: " + tag); string url = "http://search.twitter.com/search.atom?lang=en&q=%23" + tag; WWW request = new WWW(url); Debug.Log("Created request"); // Wait for download to complete yield return request; code in a new routine, which you call with yield return StartCoroutine(myurlopen()); as per the timers, you just debug.log Time.timer inside and outside of the caller and called functions.

Ah... derp. There is literally a box at the top of the profiler to "Profile Editor" I somehow never noticed that. So yeah. I can totally profile editor after all...

It looks like this was bug in Unity 3.0 and it has been fixed long time ago.