提交 6813627e 编写于 作者: T tanghai

ILRuntime的异常ToString没有带StackTrace,增加热更层的Log,Log.Error(Exception)会打印出StackTrace

上级 87c40877
namespace ETModel
using System;
namespace ETModel
{
public static class Log
{
......@@ -24,6 +26,11 @@
globalLog.Debug(message);
}
public static void Error(Exception e)
{
globalLog.Error(e.ToString());
}
public static void Error(string message)
{
globalLog.Error(message);
......
using System.Diagnostics;
using ILRuntime.Runtime;
using System;
namespace ETModel
{
......@@ -20,6 +19,11 @@ namespace ETModel
UnityEngine.Debug.Log(msg);
}
public static void Error(Exception e)
{
UnityEngine.Debug.LogError(e.ToString());
}
public static void Error(string msg)
{
UnityEngine.Debug.LogError(msg);
......
......@@ -41,18 +41,25 @@ namespace ETModel
public async void UpdateAsync()
{
TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
while (true)
{
await timerComponent.WaitAsync(waitTime);
try
{
TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
while (true)
{
await timerComponent.WaitAsync(waitTime);
if (this.IsDisposed)
{
return;
}
this.UpdateFrame();
}
if (this.IsDisposed)
{
return;
}
this.UpdateFrame();
}
}
catch (Exception e)
{
Log.Error(e);
}
}
private void UpdateFrame()
......
......@@ -90,47 +90,55 @@ namespace ETModel
continue;
}
int messageLength = udpReceiveResult.Buffer.Length;
// 长度小于4,不是正常的消息
if (messageLength < 4)
{
continue;
}
// accept
uint conn = BitConverter.ToUInt32(udpReceiveResult.Buffer, 0);
// conn从1000开始,如果为1,2,3则是特殊包
switch (conn)
try
{
case KcpProtocalType.SYN:
// 长度!=8,不是accpet消息
if (messageLength != 8)
{
int messageLength = udpReceiveResult.Buffer.Length;
// 长度小于4,不是正常的消息
if (messageLength < 4)
{
continue;
}
// accept
uint conn = BitConverter.ToUInt32(udpReceiveResult.Buffer, 0);
// conn从1000开始,如果为1,2,3则是特殊包
switch (conn)
{
case KcpProtocalType.SYN:
// 长度!=8,不是accpet消息
if (messageLength != 8)
{
break;
}
this.HandleAccept(udpReceiveResult);
break;
case KcpProtocalType.ACK:
// 长度!=12,不是connect消息
if (messageLength != 12)
{
break;
}
this.HandleConnect(udpReceiveResult);
break;
}
this.HandleAccept(udpReceiveResult);
break;
case KcpProtocalType.ACK:
// 长度!=12,不是connect消息
if (messageLength != 12)
{
case KcpProtocalType.FIN:
// 长度!=12,不是DisConnect消息
if (messageLength != 12)
{
break;
}
this.HandleDisConnect(udpReceiveResult);
break;
}
this.HandleConnect(udpReceiveResult);
break;
case KcpProtocalType.FIN:
// 长度!=12,不是DisConnect消息
if (messageLength != 12)
{
default:
this.HandleRecv(udpReceiveResult, conn);
break;
}
this.HandleDisConnect(udpReceiveResult);
break;
default:
this.HandleRecv(udpReceiveResult, conn);
break;
}
}
catch (Exception e)
{
Log.Error(e);
continue;
}
}
}
......
......@@ -13,7 +13,10 @@ namespace ILRuntime.Runtime.Generated
{
System_NotImplementedException_Binding.Register(app);
System_String_Binding.Register(app);
System_Exception_Binding.Register(app);
System_Collections_IDictionary_Binding.Register(app);
LitJson_JsonMapper_Binding.Register(app);
ETModel_Log_Binding.Register(app);
UnityEngine_LayerMask_Binding.Register(app);
UnityEngine_Input_Binding.Register(app);
UnityEngine_Camera_Binding.Register(app);
......@@ -26,7 +29,6 @@ namespace ILRuntime.Runtime.Generated
System_Runtime_CompilerServices_AsyncVoidMethodBuilder_Binding.Register(app);
System_Threading_Tasks_Task_1_ILTypeInstance_Binding.Register(app);
System_Runtime_CompilerServices_TaskAwaiter_1_ILTypeInstance_Binding.Register(app);
ETModel_Log_Binding.Register(app);
ETModel_Game_Binding.Register(app);
ETModel_Entity_Binding.Register(app);
ETModel_ResourcesComponent_Binding.Register(app);
......@@ -50,7 +52,6 @@ namespace ILRuntime.Runtime.Generated
System_Type_Binding.Register(app);
System_Reflection_MemberInfo_Binding.Register(app);
System_Activator_Binding.Register(app);
System_Exception_Binding.Register(app);
ETModel_GameObjectHelper_Binding.Register(app);
UnityEngine_TextAsset_Binding.Register(app);
//UnityEngine_Resources_Binding.Register(app);
......
......@@ -23,20 +23,23 @@ namespace ILRuntime.Runtime.Generated
Type[] args;
Type type = typeof(ETModel.Log);
args = new Type[]{typeof(System.String)};
method = type.GetMethod("Info", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Info_0);
method = type.GetMethod("Warning", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Warning_0);
args = new Type[]{typeof(System.String)};
method = type.GetMethod("Debug", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Debug_1);
method = type.GetMethod("Info", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Info_1);
args = new Type[]{typeof(System.String)};
method = type.GetMethod("Error", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Error_2);
args = new Type[]{typeof(System.String)};
method = type.GetMethod("Debug", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Debug_3);
}
static StackObject* Info_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
static StackObject* Warning_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
......@@ -45,12 +48,12 @@ namespace ILRuntime.Runtime.Generated
System.String msg = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ETModel.Log.Info(msg);
ETModel.Log.Warning(msg);
return __ret;
}
static StackObject* Debug_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
static StackObject* Info_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
......@@ -59,7 +62,7 @@ namespace ILRuntime.Runtime.Generated
System.String msg = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ETModel.Log.Debug(msg);
ETModel.Log.Info(msg);
return __ret;
}
......@@ -78,6 +81,20 @@ namespace ILRuntime.Runtime.Generated
return __ret;
}
static StackObject* Debug_3(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 1);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.String msg = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ETModel.Log.Debug(msg);
return __ret;
}
}
......
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using ILRuntime.CLR.TypeSystem;
using ILRuntime.CLR.Method;
using ILRuntime.Runtime.Enviorment;
using ILRuntime.Runtime.Intepreter;
using ILRuntime.Runtime.Stack;
using ILRuntime.Reflection;
using ILRuntime.CLR.Utils;
namespace ILRuntime.Runtime.Generated
{
unsafe class System_Collections_IDictionary_Binding
{
public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
{
BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
MethodBase method;
FieldInfo field;
Type[] args;
Type type = typeof(System.Collections.IDictionary);
args = new Type[]{typeof(System.Object)};
method = type.GetMethod("get_Item", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Item_0);
}
static StackObject* get_Item_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 2);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Object key = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Collections.IDictionary instance_of_this_method;
instance_of_this_method = (System.Collections.IDictionary)typeof(System.Collections.IDictionary).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
var result_of_this_method = instance_of_this_method[key];
object obj_result_of_this_method = result_of_this_method;
if(obj_result_of_this_method is CrossBindingAdaptorType)
{
return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance, true);
}
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method, true);
}
}
}
fileFormatVersion: 2
guid: 1962228e73e623142b4f08dd76b6e606
timeCreated: 1521084474
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -22,6 +22,9 @@ namespace ILRuntime.Runtime.Generated
FieldInfo field;
Type[] args;
Type type = typeof(System.Exception);
args = new Type[]{};
method = type.GetMethod("get_Data", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, get_Data_0);
args = new Type[]{typeof(System.String)};
method = type.GetConstructor(flag, null, args, null);
......@@ -33,6 +36,26 @@ namespace ILRuntime.Runtime.Generated
}
static StackObject* get_Data_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 1);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Exception instance_of_this_method;
instance_of_this_method = (System.Exception)typeof(System.Exception).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
var result_of_this_method = instance_of_this_method.Data;
object obj_result_of_this_method = result_of_this_method;
if(obj_result_of_this_method is CrossBindingAdaptorType)
{
return ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance);
}
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}
static StackObject* Ctor_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
{
......
......@@ -25,10 +25,10 @@ namespace ILRuntime.Runtime.Generated
args = new Type[]{typeof(System.Int32), typeof(System.Int32)};
method = type.GetMethod("Substring", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Substring_0);
args = new Type[]{typeof(System.String), typeof(System.Object)};
args = new Type[]{typeof(System.String), typeof(System.Object), typeof(System.Object)};
method = type.GetMethod("Format", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Format_1);
args = new Type[]{typeof(System.String), typeof(System.Object), typeof(System.Object)};
args = new Type[]{typeof(System.String), typeof(System.Object)};
method = type.GetMethod("Format", flag, null, args, null);
app.RegisterCLRMethodRedirection(method, Format_2);
args = new Type[]{typeof(System.String[]), typeof(System.StringSplitOptions)};
......@@ -70,15 +70,18 @@ namespace ILRuntime.Runtime.Generated
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 2);
StackObject* __ret = ILIntepreter.Minus(__esp, 3);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Object arg0 = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
System.Object arg1 = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Object arg0 = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
System.String format = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
var result_of_this_method = System.String.Format(format, arg0);
var result_of_this_method = System.String.Format(format, arg0, arg1);
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}
......@@ -87,18 +90,15 @@ namespace ILRuntime.Runtime.Generated
{
ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
StackObject* ptr_of_this_method;
StackObject* __ret = ILIntepreter.Minus(__esp, 3);
StackObject* __ret = ILIntepreter.Minus(__esp, 2);
ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
System.Object arg1 = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.Object arg0 = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
System.String format = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
__intp.Free(ptr_of_this_method);
var result_of_this_method = System.String.Format(format, arg0, arg1);
var result_of_this_method = System.String.Format(format, arg0);
return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
}
......
using System;
using ETModel;
namespace ETHotfix
{
public static class ExceptionHelper
{
public static string ToStr(this Exception exception)
{
#if ILRuntime
return $"{exception.Data["StackTrace"]} \n\n {exception}";
#else
return exception.ToString();
#endif
}
}
}
\ No newline at end of file
using System;
namespace ETHotfix
{
public static class Log
{
public static void Warning(string msg)
{
ETModel.Log.Warning(msg);
}
public static void Info(string msg)
{
ETModel.Log.Info(msg);
}
public static void Error(Exception e)
{
ETModel.Log.Error(e.ToStr());
}
public static void Error(string msg)
{
ETModel.Log.Error(msg);
}
public static void Debug(string msg)
{
ETModel.Log.Debug(msg);
}
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ namespace ETHotfix
}
catch (Exception e)
{
Log.Error(e.ToString());
Log.Error(e);
}
}
......@@ -44,7 +44,7 @@ namespace ETHotfix
}
catch (Exception e)
{
Log.Error(e.ToString());
Log.Error(e);
}
}
......@@ -56,7 +56,7 @@ namespace ETHotfix
}
catch (Exception e)
{
Log.Error(e.ToString());
Log.Error(e);
}
}
......
using ETModel;
using System;
using ETModel;
using UnityEngine;
namespace ETHotfix
......@@ -51,9 +52,16 @@ namespace ETHotfix
public async void TestActor()
{
M2C_TestActorResponse response = (M2C_TestActorResponse)await SessionWrapComponent.Instance.Session.Call(
new C2M_TestActorRequest() {Info = "actor rpc request"});
Log.Info(response.Info);
try
{
M2C_TestActorResponse response = (M2C_TestActorResponse)await SessionWrapComponent.Instance.Session.Call(
new C2M_TestActorRequest() { Info = "actor rpc request" });
Log.Info(response.Info);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}
......@@ -54,7 +54,7 @@ namespace ETHotfix
}
catch (Exception e)
{
Log.Error(e.ToString());
Log.Error(e);
}
}
......@@ -67,7 +67,7 @@ namespace ETHotfix
}
catch (Exception e)
{
Log.Error(e.ToString());
Log.Error(e);
}
}
......@@ -86,7 +86,7 @@ namespace ETHotfix
}
catch (Exception e)
{
Log.Error(e.ToString());
Log.Error(e);
}
}
}
......
......@@ -61,7 +61,7 @@ namespace ETHotfix
catch (Exception e)
{
sessionWrap?.Dispose();
Log.Error(e.ToString());
Log.Error(e);
}
}
}
......
......@@ -53,7 +53,9 @@
<Compile Include="Base\Event\IEvent.cs" />
<Compile Include="Base\Helper\ArrayHelper.cs" />
<Compile Include="Base\Helper\AssetBundleHelper.cs" />
<Compile Include="Base\Helper\ExceptionHelper.cs" />
<Compile Include="Base\Helper\JsonHelper.cs" />
<Compile Include="Base\Helper\Log.cs" />
<Compile Include="Base\Object\IStart.cs" />
<Compile Include="Module\FrameSync\OperaComponent.cs" />
<Compile Include="Entity\Config\UnitConfig.cs" />
......
......@@ -412,6 +412,7 @@
<Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_Generic_List_1_UnitInfo_Binding.cs" />
<Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_Generic_List_1_UnitInfo_Binding_Enumerator__t.cs" />
<Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_Generic_Queue_1_ILTypeInstance_Binding.cs" />
<Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Collections_IDictionary_Binding.cs" />
<Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Exception_Binding.cs" />
<Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_IDisposable_Binding.cs" />
<Compile Include="Assets\ThirdParty\ILRuntime\Generated\System_Linq_Enumerable_Binding.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册