UnityWebRequest isDone crash

Hi guys,

I recently tried to adapt part of our web requests to use UnityWebRequests throughout our project and came across a weird issue.

Part of the code was yielding the result and worked just fine but I tried to use the isDone and downloadProgress properties to report progress and got a 100% editor crash when doing so.

Here is the old working code :

using (UnityWebRequest request = new UnityWebRequest(Url, Method))
{
	var it = headers.GetEnumerator();
	while (it.MoveNext())
	{
		var entry = it.Current;
		request.SetRequestHeader(entry.Key, entry.Value);
	}
	if (body != null)
	{
		UploadHandler upload = new UploadHandlerRaw(body);
		request.uploadHandler = upload;
	}
	DownloadHandler download = new DownloadHandlerBuffer();
	request.downloadHandler = download;
	yield return request.Send();
	response = new WebRequestResponse(request);
}

Here’s the code that creates a crash of the editor :

using (UnityWebRequest request = new UnityWebRequest(Url, Method))
{
	var it = headers.GetEnumerator();
	while (it.MoveNext())
	{
		var entry = it.Current;
		request.SetRequestHeader(entry.Key, entry.Value);
	}
	if (body != null)
	{
		UploadHandler upload = new UploadHandlerRaw(body);
		request.uploadHandler = upload;
	}
	DownloadHandler download = new DownloadHandlerBuffer();
	request.downloadHandler = download;
	request.Send();
	while (request.isDone == false)
	{
		Progress = request.downloadProgress;
		yield return null;
	}
	response = new WebRequestResponse(request);
}

And most surprising of all to me is that we found a workaround doing this :

using (UnityWebRequest request = new UnityWebRequest(Url, Method))
{
	var it = headers.GetEnumerator();
	while (it.MoveNext())
	{
		var entry = it.Current;
		request.SetRequestHeader(entry.Key, entry.Value);
	}
	if (body != null)
	{
		UploadHandler upload = new UploadHandlerRaw(body);
		request.uploadHandler = upload;
	}
	DownloadHandler download = new DownloadHandlerBuffer();
	request.downloadHandler = download;
	AsyncOperation op = request.Send();
	while (op.isDone == false)
	{
		Progress = op.progress;
		yield return null;
	}
	response = new WebRequestResponse(request);
}

(Not sure the isDone and progress properties are good in this case though)
It does look like a bug in the editor to me, does any of you have more info on that or should I report a bug?

I’m working on a simple repro case right now.

Thanks!

Edit : As expected I couldn’t create a “simple” repro case as it’s probably a mix of specific requests at various frequencies during gameplay. Still, the fact that the editor itself crashes is a problem that souldn’t happen even if we have some scripting mistakes/bad practices

Hi,

I’m also using UnityWebRequests in the editor, and had the problem that I would never get a response using UnityWebRequest.isDone()

Other people seem to also have problems with it, albeit slightly different.

However, your workaround of assigning the result of UnityWebRequest.Send() to an AsyncOperation, then checking isDone() on that, also works for me - bizarre!

checking either isDone in my Update() still crashed, but if I put an unholy Thread.Sleep(1) before I used the data I was ok.