Jelajahi Sumber

修复CodeLoader中appDomain没有Dispose导致客户端退出卡死的问题

tanghai 4 tahun lalu
induk
melakukan
84782f9f2d

+ 9 - 2
Unity/Assets/Mono/CodeLoader.cs

@@ -7,7 +7,7 @@ using System.Linq;
 
 
 namespace ET
 namespace ET
 {
 {
-	public class CodeLoader
+	public class CodeLoader: IDisposable
 	{
 	{
 		public static CodeLoader Instance = new CodeLoader();
 		public static CodeLoader Instance = new CodeLoader();
 
 
@@ -16,6 +16,8 @@ namespace ET
 		public Action OnApplicationQuit;
 		public Action OnApplicationQuit;
 
 
 		private Assembly assembly;
 		private Assembly assembly;
+
+		private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
 		
 		
 		private Type[] allTypes;
 		private Type[] allTypes;
 		
 		
@@ -24,6 +26,11 @@ namespace ET
 		private CodeLoader()
 		private CodeLoader()
 		{
 		{
 		}
 		}
+
+		public void Dispose()
+		{
+			this.appDomain?.Dispose();
+		}
 		
 		
 		public void Start()
 		public void Start()
 		{
 		{
@@ -50,7 +57,7 @@ namespace ET
 					//byte[] assBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.dll"));
 					//byte[] assBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.dll"));
 					//byte[] pdbBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.pdb"));
 					//byte[] pdbBytes = File.ReadAllBytes(Path.Combine("../Unity/", Define.BuildOutputDir, "Code.pdb"));
 				
 				
-					ILRuntime.Runtime.Enviorment.AppDomain appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
+					appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
 					MemoryStream assStream = new MemoryStream(assBytes);
 					MemoryStream assStream = new MemoryStream(assBytes);
 					MemoryStream pdbStream = new MemoryStream(pdbBytes);
 					MemoryStream pdbStream = new MemoryStream(pdbBytes);
 					appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());
 					appDomain.LoadAssembly(assStream, pdbStream, new ILRuntime.Mono.Cecil.Pdb.PdbReaderProvider());

+ 1 - 0
Unity/Assets/Mono/MonoBehaviour/Init.cs

@@ -57,6 +57,7 @@ namespace ET
 		private void OnApplicationQuit()
 		private void OnApplicationQuit()
 		{
 		{
 			CodeLoader.Instance.OnApplicationQuit();
 			CodeLoader.Instance.OnApplicationQuit();
+			CodeLoader.Instance.Dispose();
 		}
 		}
 	}
 	}
 }
 }

+ 1 - 1
Unity/Unity.Mono.csproj

@@ -138,8 +138,8 @@
      <Compile Include="Assets\Mono\ILRuntime\Generate\ET_AService_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\ET_AService_Binding.cs" />
      <Compile Include="Assets\Mono\Module\Message\RpcException.cs" />
      <Compile Include="Assets\Mono\Module\Message\RpcException.cs" />
      <Compile Include="Assets\Mono\ILRuntime\ILStaticMethod.cs" />
      <Compile Include="Assets\Mono\ILRuntime\ILStaticMethod.cs" />
-     <Compile Include="Assets\Mono\ILRuntime\Generate\ET_ETAsyncTaskMethodBuilder_1_Object_Array_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\System_Collections_Generic_HashSet_1_UInt16_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\System_Collections_Generic_HashSet_1_UInt16_Binding.cs" />
+     <Compile Include="Assets\Mono\ILRuntime\Generate\ET_ETAsyncTaskMethodBuilder_1_Object_Array_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\UnityEngine_LayerMask_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\UnityEngine_LayerMask_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\System_Collections_Generic_List_1_ETTask_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\System_Collections_Generic_List_1_ETTask_Binding.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\System_Collections_Generic_Dictionary_2_Int64_ILTypeInstance_Binding__t1.cs" />
      <Compile Include="Assets\Mono\ILRuntime\Generate\System_Collections_Generic_Dictionary_2_Int64_ILTypeInstance_Binding__t1.cs" />