diff --git a/Server/Hotfix/Other/EntityActorHandler.cs b/Server/Hotfix/Other/EntityActorHandler.cs index 56ebaefdc73c63c69fa578bfc63bcb77e032eace..d1a66c7173473b463e6b1170d77557a730adcffc 100644 --- a/Server/Hotfix/Other/EntityActorHandler.cs +++ b/Server/Hotfix/Other/EntityActorHandler.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Model; namespace Hotfix @@ -10,12 +11,21 @@ namespace Hotfix { public async Task Handle(Session session, Entity entity, ActorRequest message) { - ((Session)entity).Send(message.AMessage); - ActorResponse response = new ActorResponse - { - RpcId = message.RpcId - }; - session.Reply(response); + ActorResponse response = new ActorResponse { RpcId = message.RpcId }; + + try + { + ((Session)entity).Send(message.AMessage); + session.Reply(response); + await Task.CompletedTask; + } + catch (Exception e) + { + response.Error = ErrorCode.ERR_SessionActorError; + response.Message = $"session actor error {e}"; + session.Reply(response); + throw; + } } } diff --git a/Server/Hotfix/System/ActorComponentSystem.cs b/Server/Hotfix/System/ActorComponentSystem.cs index 526fbec83be89b51dc1237a9aa5661982dfcd82b..48a209f983cc641cfa451d3b0d10530f116c0faa 100644 --- a/Server/Hotfix/System/ActorComponentSystem.cs +++ b/Server/Hotfix/System/ActorComponentSystem.cs @@ -90,10 +90,14 @@ namespace Hotfix { while (true) { + if (self.Id == 0) + { + return; + } try { ActorMessageInfo info = await self.GetAsync(); - await self.entityActorHandler.Handle(info.Session, self.Entity, info.Message); + await self.entityActorHandler.Handle(info.Session, self.Entity, info.Message); } catch (Exception e) { diff --git a/Server/Model/Base/Message/ErrorCode.cs b/Server/Model/Base/Message/ErrorCode.cs index 2d91c0e936b98a440e34c3fc624fe75b6f3a9e03..ca44b57720d6d21a5aa57fabc51fc32761b1507e 100644 --- a/Server/Model/Base/Message/ErrorCode.cs +++ b/Server/Model/Base/Message/ErrorCode.cs @@ -12,5 +12,7 @@ namespace Model public const int ERR_ReloadFail = 104; public const int ERR_NotFoundUnit = 105; public const int ERR_ActorLocationNotFound = 106; + public const int ERR_SessionActorError = 107; + public const int ERR_ActorError = 108; } } \ No newline at end of file diff --git a/Server/Model/Component/ActorComponent.cs b/Server/Model/Component/ActorComponent.cs index f094a2b645f699933bc54fd36ece46783cd96e4d..455330b6ade41a7848d8d446486cb74c41015043 100644 --- a/Server/Model/Component/ActorComponent.cs +++ b/Server/Model/Component/ActorComponent.cs @@ -34,6 +34,8 @@ namespace Model base.Dispose(); + this.tcs?.SetException(new Exception($"actor disposed! {this.actorId}")); + Game.Scene.GetComponent().Remove(actorId); } catch (Exception) diff --git a/Unity/Assets/Scripts/Base/Log.cs b/Unity/Assets/Scripts/Base/Log.cs index f7465c139a3b72cb4c5e07948ebcbe7fb7fa4909..7096484fa86d04f20c769b78d19ac593397bf996 100644 --- a/Unity/Assets/Scripts/Base/Log.cs +++ b/Unity/Assets/Scripts/Base/Log.cs @@ -21,7 +21,7 @@ { UnityEngine.Debug.Log(msg); } - + public static void Flush() { }