Skip to content

Commit

Permalink
修改执行问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed Sep 19, 2017
1 parent acfa770 commit 1bb9597
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions unity/Assets/Script/Core/GameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class GameWorld : MonoBehaviour
private readonly Queue<ToExecute> _toExecuteQueue = new Queue<ToExecute>();
private readonly List<Action> _applicationQuitActionList = new List<Action>();

private static readonly object _locker = new object();
private void Awake()
{
Instance = this;
Expand All @@ -43,9 +44,9 @@ private void Update()
Facade.GameTick.OnTick();
if (_toExecuteQueue.Count > 0)
{
lock (_toExecuteQueue)
lock (_locker)
{
for (int i = 0; i < _toExecuteQueue.Count; i++)
while (_toExecuteQueue.Count>0)
{
var per = _toExecuteQueue.Dequeue();
per.Action(per.Obj);
Expand Down Expand Up @@ -81,7 +82,7 @@ void OnApplicationPause(bool pause)

public void RunOnMainThread(Action<object> action, object obj)//obj不能可选为空,数据会被线程冲刷,需要传递原有数据
{
lock (_toExecuteQueue)
lock (_locker)
{
_toExecuteQueue.Enqueue(new ToExecute(action, obj));
}
Expand Down

0 comments on commit 1bb9597

Please sign in to comment.