I use a lot WWW class for http request with my server and it seems it causes the game to terminate itself sometimes. My game is rejected because of that and I don't know what is wrong cause this code works very well on any other platforms, iOS, android and windows phone. There must be something in http request handling that causes the crash but the console output isn't really helpfull, I got things like this when it crashes: [21.854279] HTTP status Code is 200 [21.854792] HTTP start transfer of unknown size [21.864551] HTTP end transfer [21.867631] HTTP Done downloading [21.868067] HTTP Done downloading [21.868465] HTTP Done downloading [21.869813] HTTP Done downloading [21.870241] HTTP Done downloading I don't know with I got 5 times "HTTP Done downloading" for just 1 request... I'm stuck here Any ideas?
Yes : Code (CSharp): public class Webrequest : MonoBehaviour { private static string baseurl = "http://live.latest.something.appspot.com/"; private static string betaurl = "http://dev.latest.something.appspot.com/"; public delegate void RequestResponseDelegate(RequestStatus s, string response, object dico); protected RequestResponseDelegate dlg = null; public enum RequestStatus { RequestFailed, RequestSucceeded } public Webrequest() { } public void SendJsonRequest(string action, string parameters, RequestResponseDelegate d) { dlg = d; string url = (Data.distribution ? baseurl : (Data.betaserver ? betaurl : baseurl)) + action; WWWForm form = new WWWForm(); form.AddField(@"data", parameters); WWW www = new WWW(url, form); if (!Data.distribution) ConsoleLog.Log("Calling " + url + " with Params: " + parameters); StartCoroutine(WaitForPostRequest(www)); } protected IEnumerator WaitForPostRequest(WWW www) { yield return www; // check for errors if (www.error == null) { /* if (!Data.distribution) ConsoleLog.Log("WWW Ok!: " + www.text); */ if (dlg != null) { dlg(RequestStatus.RequestSucceeded, www.text, www.text.dictionaryFromJson()); } } else { ConsoleLog.Log("WWW Error: " + www.error + " (" + www.url + ")"); if (dlg != null) dlg(RequestStatus.RequestFailed, www.error, null); } EventManager.Instance.InvokeNextFrame( () => { StopCoroutine("WaitForPostRequest"); UnityEngine.GameObject.Destroy(this); }); } }
From what I can see the StopCoroutine will not work as this only works for Co routines STARTED with a string i.e. you would have needed to start your co routine with this StartCoroutine("WaitForPostRequest"); I'm also not sure what stopping a co-routine with a call from within that co-routine will do as I've never tried that.
Thanks for this I don't know how I could miss that! So now I start the coroutine with StartCoroutine("WaitForPostRequest", www); It seems it crash less often, but still crashes a while afterwards...
If it crashes less often now.. is it something else in your project that is also contributing towards crashing? Whats the console outputs say now.
well it was just an impression, finally it crashes about the same... I put a Testproject that reproduce the crash here : http://community.eu.playstation.com/t5/General/Random-crashes-when-using-WWW-class/td-p/22186975
You have so many plugins and scripts in that test project >_< have you tried that one google analytics script (i presume its that one your on about) on a completely blank project, no other scripts or plugins etc.
hmm no, you think it comes from that plugin? I know I have many plugins, it's hard to strip them off the project
Make a blank project from scratch, and add that one google analytics script/s. I know a lot of plugins don't work with PSM (at the moment) so i do think its one of them
The version of Google Analytics doesn't seem to be compatible with 4.3 as it's failing to even build under it. The error seems to be that WWW can't convert param 3 i.e. the header from a dictionary<string, string> to a hashtable. Where did you get this version of google analytics. Have you checked that it doesn't require unity 4.5 or something like that.
It's building fine with last version of Unity PSM. I think I made a #define to switch easily between dictionary and hashtable. Anyway I tested after removing this plugin and it crashes the same, I think the problem comes from everything that is using WWW class. I use it a lot even without this google analytics problem. I don't know why it crashes uniquely on the ps vita... It should'nt because it's working fine on every other platform.
I've done some testing at my end and it looks like it's the Unity WWW class that is the issue. I can usually download just fine but, get weird errors from time to time almost as if I'm clashing with some process of the vita OS. Have you raised a bug with the unity guys? I suspect they need to make some changes to get WWW working consistently on a Vita.
Yeah I think there is a problem with WWW class on vita too... I sent a message to a PSM Dev Support on playstation forums but no news yet. How can I raise this bug to unity guys?
The general answer is outlined here : https://psm.playstation.net/static/...en/Documentation/Manual/PSMReportingBugs.html But I've downloaded your repro project from the PSM forums, and will have a look at it shortly.
@madgreg Turns out this is not at all related to your webrequests. Instead it's a very old bug in the Dispose method of MD5CryptoServiceProvider (actually still present in the latest Mono corlibs from what I can see). Creating multiple MD5CryptoServiceProvider objects (more than 5-10) before the GC kicks in causes a crash in the GC finalizer. The problem is resolved now, and the next release will include the fix. Currently the only workaround is to not use MD5CryptoServiceProvider (or at least make sure the object is not destroyed)..
Um I don't remember ever even creating one let alone storing a reference to it. Am I missing something?