Only Use Il2cpp will crash sometimes ,wont with mono,about 20% percentage in sub thread. Now my unity version is 5.2.3. Error is EXC_BAD_ACCESS ,maybe object had released release again. some objects will be release in sub thread and il2cpp VM? I need Some Help,that's my Code:
MiniTuple curRequest = new MiniTuple() ;
lock(m_lock)
{
if(requestList.Count >0)
{
curRequest =requestList.Pop();
}
}
if (string.IsNullOrEmpty( curRequest.field0))
{
LogMgr.LogError("Is Empty");
return;
}
int trytimes = 2;
Action> postevent = delegate(MiniTuple RequestData )
{
MiniTuple> temp = (MiniTuple>)RequestData.field2;
HttpWebRequest req = null;
HttpWebResponse Response = null;
string url=RequestData.field0;
if (RequestData.field1 == HttpType.POST)
{
req = HttpWebRequest.Create(url) as HttpWebRequest;
req.Timeout = Config.mIns.Http_TimeOut;
req.Method = "POST";
req.Accept ="text/html, application/xhtml+xml, */*";
byte[] btBodys = System.Text.Encoding.UTF8.GetBytes(temp.field0);
if ( btBodys.Length >0 && req != null)
{
req.ContentLength = btBodys.Length;
Stream respSb = req.GetRequestStream();
respSb.Write(btBodys, 0, btBodys.Length);
respSb.Close();
}
}
else if (RequestData.field1 == HttpType.GET)
{
req = (HttpWebRequest)HttpWebRequest.Create(url +"?"+temp.field0);
req.Timeout = Config.mIns.Http_TimeOut;
req.ContentType = "application/x-www-form-urlencoded,application/json";
req.Accept ="*/*";
req.Method = "GET";
}
if(req != null)
{
Response = (HttpWebResponse)req.GetResponse();
var sr = new StreamReader(Response.GetResponseStream());
string responseContent = sr.ReadToEnd();
if (temp.field1 != null)
{
temp.field1(responseContent);
}
// LogMgr.Log("收到请求");
trytimes = 0;
req.Abort();
sr.Close();
Response.Close();
}
};
Action> httpCall = null;
httpCall = delegate(MiniTuple RequestData) {
try
{
postevent(RequestData);
}
catch (Exception webEx)
{
LogMgr.LogError(webEx);
if (webEx is WebException)
{
var ex = webEx as WebException;
if (ex.Status == WebExceptionStatus.Timeout && trytimes > 0)
{
trytimes--;
httpCall(RequestData);
}
else
{
DealWithEx(webEx);
}
}
else
DealWithEx(webEx);
}
};
httpCall(curRequest);
It works in sub thread ,and it will crash when HttpWebRequest.Create xxxxx ,may be bug?- - or my error?
↧