Browse Source

【BUG】游戏战斗程序内存泄漏问题

meijun 3 years ago
parent
commit
067d57822f

+ 5 - 2
Common/CommonAI/Zone/EventTrigger/EventAdapter.cs

@@ -207,9 +207,12 @@ namespace CommonAI.Zone.EventTrigger
 			foreach (var t in mData.EventActions) { if (t != null) t.Dispose(); }
 			foreach (TimeTaskMS task in mTimes)
 			{
-				task.Stop();
+				task.Dispose();
 			}
-			if (mOnDisposed != null)
+			mTimes.Clear();
+			mTimes = null;
+
+            if (mOnDisposed != null)
 			{
 				mOnDisposed.Invoke(this);
 			}

+ 1 - 0
Common/CommonAI/Zone/Instance/InstanceFlag.cs

@@ -276,6 +276,7 @@ namespace CommonAI.Zone.Instance
             mViewTrigger.Dispose();
             foreach (var e in mSpawnTriggers)
             {
+				e.OnLastObjectRemoved -= onTriggerLastObjectRemoved;
                 e.Dispose();
             }
             mSpawnTriggers.Clear();

+ 20 - 3
Common/CommonAI/Zone/Instance/InstanceSpell.cs

@@ -22,7 +22,7 @@ namespace CommonAI.Zone.Instance
         readonly protected InstanceUnit mLauncherUnit;
         // 发出者
         readonly protected InstanceZoneObject mSender;
-        readonly protected AttackRangeHelper AttackRange;
+        protected AttackRangeHelper AttackRange;
 
         protected Vector2 mStartPos;
         protected float mLaunchDirection;
@@ -428,7 +428,21 @@ namespace CommonAI.Zone.Instance
 				this.mCurveSpellList = null;
 			}
 
-			base.Disposing();
+			if(brothers != null)
+			{
+				for(int i = 0; i < brothers.Length; i++)
+				{
+					if(this == brothers[i])
+					{
+						brothers[i] = null;
+						break;
+					}					
+                }
+            }
+
+			this.AttackRange = null;
+
+            base.Disposing();
 		}
 
 		protected override void onRemoved()
@@ -1005,7 +1019,10 @@ namespace CommonAI.Zone.Instance
             }
             foreach (var b in brothers)
             {
-                b.foxfireSeekWait += timeValue;
+				if(b != null)
+				{
+					b.foxfireSeekWait += timeValue;
+				}                
             }
         }
 

+ 14 - 14
Common/CommonAI/Zone/Instance/InstanceZone.API.cs

@@ -253,20 +253,20 @@ namespace CommonAI.Zone.Instance
             return GetEditFlag(name);
         }
 
-        public TimeTaskMS add_time_task_ms(int interval, int delay, int repeat, TickHandler handler)
-        {
-            return AddTimeTask(interval, delay, repeat, handler);
-        }
-
-        public TimeTaskMS add_time_delay_ms(int delay, TickHandler handler)
-        {
-            return AddTimeDelayMS(delay, handler);
-        }
-
-        public TimeTaskMS add_time_periodic_ms(int interval, TickHandler handler)
-        {
-            return AddTimePeriodicMS(interval, handler);
-        }
+        //public TimeTaskMS add_time_task_ms(int interval, int delay, int repeat, TickHandler handler)
+        //{
+        //    return AddTimeTask(interval, delay, repeat, handler);
+        //}
+
+        //public TimeTaskMS add_time_delay_ms(int delay, TickHandler handler)
+        //{
+        //    return AddTimeDelayMS(delay, handler);
+        //}
+
+        //public TimeTaskMS add_time_periodic_ms(int interval, TickHandler handler)
+        //{
+        //    return AddTimePeriodicMS(interval, handler);
+        //}
 
         public void do_client_script(string filename)
         {

+ 10 - 10
Common/CommonAI/Zone/ZoneEditor/EditorTemplates.cs

@@ -622,16 +622,16 @@ namespace CommonAI.Zone.ZoneEditor
 		/// </summary>
 		public void CacheAllScenes()
         {
-            foreach (int scene_id in ListScenes())
-            {
-				SceneData sceneTemp = this.CacheScene_Server(scene_id);
-				if(sceneTemp == null)
-				{
-					log.Error("缓存场景异常:" + scene_id);
-					continue;
-				}
-				this.mCacheScenes.Put(scene_id, sceneTemp);
-			}
+   //         foreach (int scene_id in ListScenes())
+   //         {
+			//	SceneData sceneTemp = this.CacheScene_Server(scene_id);
+			//	if(sceneTemp == null)
+			//	{
+			//		log.Error("缓存场景异常:" + scene_id);
+			//		continue;
+			//	}
+			//	this.mCacheScenes.Put(scene_id, sceneTemp);
+			//}
 
 
 			//List<SceneData> ret = new List<SceneData>(scenes.Values);

+ 1 - 1
Common/CommonAI/ZoneServer/JSGModule/JSGServerProfile.cs

@@ -45,7 +45,7 @@ namespace CommonAI.ZoneServer.JSGModule
 		}
 
 		protected static readonly Logger log = LoggerFactory.GetDefLogger();
-		private static readonly int STRIGGER_INTERVAL = 3600 * 1000;
+		private static readonly int STRIGGER_INTERVAL = 600 * 1000;
 
 		//////////////////////////////////////////////////////////////////////////////////
 		//数据统计		

+ 18 - 3
Common/CommonLang/Timing.cs

@@ -201,7 +201,7 @@ namespace CommonLang
 
     public class TimeTaskMS
     {
-        readonly private TickHandler Handler;
+        private TickHandler Handler;
         readonly private int IntervalTimeMS;
         readonly private int DelayTimeMS;
         readonly private int RepeatCount;
@@ -289,7 +289,14 @@ namespace CommonLang
         public void Stop()
         {
             mExit = true;
-        }
+			
+		}
+
+		public void Dispose()
+		{
+            mExit = true;
+			this.Handler = null;
+		}
 
         public void Pause()
         {
@@ -330,7 +337,6 @@ namespace CommonLang
             invoking.Clear();
         }
 
-
         public void Update(int intervalMS)
         {
             removed.Clear();
@@ -366,6 +372,15 @@ namespace CommonLang
                     task.TryInvoke();
                 }
             }
+
+            // 手动调用一下dispose
+            if (removed.Count > 0)
+            {
+                for (int i = removed.Count - 1; i >= 0; --i)
+                {
+                    removed[i].Value.Dispose();
+                }
+            }
         }
 
         /// <summary>

+ 2 - 2
XmdsCommonServer/Plugin/Quest/QuestScript.cs

@@ -20,7 +20,7 @@ namespace XmdsCommonServer.Plugin.Quest
     {
         protected readonly static Logger log = LoggerFactory.GetLogger("QuestScript");
         private string m_QuestID;
-        private int m_QuestType;
+        //private int m_QuestType;
 
         private XmdsInstancePlayer m_Player;
         private XmdsServerScene m_Zone;
@@ -38,7 +38,7 @@ namespace XmdsCommonServer.Plugin.Quest
         /// <summary>
         /// 触发的任务类型
         /// </summary>
-        public int QuestType { get { return m_QuestType; } }
+        //public int QuestType { get { return m_QuestType; } }
         /// <summary>
         /// 触发任务的玩家实体
         /// </summary>

+ 2 - 2
XmdsServerCS/XmdsServerEdgeJS/Zone/ZoneService.cs

@@ -154,8 +154,8 @@ namespace XmdsServerEdgeJS.Zone
 				{
 					try
 					{
-						log.Info("场景ID:" + p.InstanceID + ", " + p.Node.GetBindGameSrvId() + ", 场景ID: " + p.Node.SceneID + ", units=" + p.Node.Zone.AllUnitsCount
-							+ ", spells=" + p.Node.Zone.AllSpellsCount + ", items=" + p.Node.Zone.AllItemsCount);
+						log.Info("PrintAllSceneInfo-ID:" + p.InstanceID + ", " + p.Node.GetBindGameSrvId() + ", 场景ID: " + p.Node.SceneID + ", units=" + p.Node.Zone.AllUnitsCount
+							+ ", spells=" + p.Node.Zone.AllSpellsCount + ", items=" + p.Node.Zone.AllItemsCount + ", task: " + p.Node.Zone.GetTimeTaskInfo());
 					}
 					catch (Exception e)
 					{

+ 9 - 5
XmdsServerCS/XmdsServerNode/CheatingDeath/MoveSpeedChecker.cs

@@ -1,4 +1,5 @@
-using CommonAI.RTS;
+using CommonAI;
+using CommonAI.RTS;
 using CommonAI.Zone;
 using CommonAI.Zone.Helper;
 using CommonAI.Zone.Instance;
@@ -39,12 +40,16 @@ namespace XmdsServerNode.CheatingDeath
             this.mLastPos.SetY(mActor.Y);
         }
 
-        private void MActor_OnRemoved(InstanceUnit unit)
+
+		private void MActor_OnRemoved(InstanceUnit unit)
         {
             this.mActor.OnUpdate -= MActor_OnUpdate;
             this.mActor.OnObjectSendingEvent -= MActor_OnObjectSendingEvent;
             this.mActor.OnHandleAction -= MActor_OnHandleAction;
-        }
+
+			this.mActor.OnRemoved -= MActor_OnRemoved;
+			this.mActor.OnRegionTransport -= MActor_OnRegionTransport;
+		}
 
 		private void MActor_OnRegionTransport()
 		{
@@ -157,6 +162,5 @@ namespace XmdsServerNode.CheatingDeath
             //    expectDistance
             //    ));
         }
-
-    }
+	}
 }

+ 39 - 39
XmdsVSPlugins/XmdsCommonQuest/Quest/Quest_RefineSoul.cs

@@ -106,36 +106,36 @@ namespace XmdsCommonQuest.Quest
             }
         }
 
-        private void AddRefineItem(Vector2 pos)
-        {
-            if (mRefineItem != null)
-            {
-                mRefineItem.setPos(pos.X, pos.Y);
-                mRefineItem.SendForceSync();
-            }
-            else
-            {
-                var itemInfo = Zone.Templates.getItem(mRefineItemTemplateID);
-                if (itemInfo != null)
-                {
-                    //uuid 作为name同步到客户端,以便客户端隐藏/显示
-                    mRefineItem = Zone.AddItem(itemInfo, Player.PlayerUUID, pos.X, pos.Y, Player.Direction, Player.Force, Player.PlayerUUID, null);
-                    mRefineItem.OnTryPickItem += MRefineItem_OnTryPickItem;
-                    mRefineItem.OnObjectRemoved += MRefineItem_OnObjectRemoved;
-                }
-            }
-            var q = Player.GetQuest(QuestID);
+        //private void AddRefineItem(Vector2 pos)
+        //{
+        //    if (mRefineItem != null)
+        //    {
+        //        mRefineItem.setPos(pos.X, pos.Y);
+        //        mRefineItem.SendForceSync();
+        //    }
+        //    else
+        //    {
+        //        var itemInfo = Zone.Templates.getItem(mRefineItemTemplateID);
+        //        if (itemInfo != null)
+        //        {
+        //            //uuid 作为name同步到客户端,以便客户端隐藏/显示
+        //            mRefineItem = Zone.AddItem(itemInfo, Player.PlayerUUID, pos.X, pos.Y, Player.Direction, Player.Force, Player.PlayerUUID, null);
+        //            mRefineItem.OnTryPickItem += MRefineItem_OnTryPickItem;
+        //            //mRefineItem.OnObjectRemoved += MRefineItem_OnObjectRemoved;
+        //        }
+        //    }
+        //    var q = Player.GetQuest(QuestID);
 
-            if (string.IsNullOrEmpty(q.Attributes.Get(Attribute_Killed)))
-            {
-                State = RefineState.Progress;
-            }
-            else
-            {
-                State = RefineState.GetReady;
-            }
+        //    if (string.IsNullOrEmpty(q.Attributes.Get(Attribute_Killed)))
+        //    {
+        //        State = RefineState.Progress;
+        //    }
+        //    else
+        //    {
+        //        State = RefineState.GetReady;
+        //    }
 
-        }
+        //}
 
         private void RefineItem_Tick(TimeTaskMS task)
         {
@@ -270,17 +270,17 @@ namespace XmdsCommonQuest.Quest
 
         public override bool TryDoAction(ObjectAction act)
         {
-            if (act is PlayerPutRefineSoulItemAction && !Virtual.IsInSafeArea())
-            {
-                Vector2 pos = CalcNextRefineItemPos();
-                int gx = 0, gy = 0;
-                Zone.PathFinder.PosToBlock(pos.X, pos.Y, out gx, out gy);
-                if(!Zone.PathFinder.TouchMapBlock(gx, gy))
-                {
-                    AddRefineItem(pos);
-                }              
-                return true;
-            }
+            //if (act is PlayerPutRefineSoulItemAction && !Virtual.IsInSafeArea())
+            //{
+            //    Vector2 pos = CalcNextRefineItemPos();
+            //    int gx = 0, gy = 0;
+            //    Zone.PathFinder.PosToBlock(pos.X, pos.Y, out gx, out gy);
+            //    if(!Zone.PathFinder.TouchMapBlock(gx, gy))
+            //    {
+            //        AddRefineItem(pos);
+            //    }              
+            //    return true;
+            //}
             return false;
         }
 

+ 1 - 1
test/app.config

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <configuration>
   <appSettings>
-    <add key="zoneConfig.assetPath" value="D:\Xmds_TEMP\GameEditors\GameEditor\data" />
+    <add key="zoneConfig.assetPath" value="D:\XMDS_TEMP\GameEditors\GameEditor\data" />
     <add key="logConfig.configFile" value="log4net" />
     <add key="logConfig.serverId" value="csharp-server-11" />
     <add key="logConfig.outputPath" value="../log/" />