Skip to content

Commit 1bb9597

Browse files
author
Hiram
committed
修改执行问题
1 parent acfa770 commit 1bb9597

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

unity/Assets/Script/Core/GameWorld.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class GameWorld : MonoBehaviour
1818
private readonly Queue<ToExecute> _toExecuteQueue = new Queue<ToExecute>();
1919
private readonly List<Action> _applicationQuitActionList = new List<Action>();
2020

21+
private static readonly object _locker = new object();
2122
private void Awake()
2223
{
2324
Instance = this;
@@ -43,9 +44,9 @@ private void Update()
4344
Facade.GameTick.OnTick();
4445
if (_toExecuteQueue.Count > 0)
4546
{
46-
lock (_toExecuteQueue)
47+
lock (_locker)
4748
{
48-
for (int i = 0; i < _toExecuteQueue.Count; i++)
49+
while (_toExecuteQueue.Count>0)
4950
{
5051
var per = _toExecuteQueue.Dequeue();
5152
per.Action(per.Obj);
@@ -81,7 +82,7 @@ void OnApplicationPause(bool pause)
8182

8283
public void RunOnMainThread(Action<object> action, object obj)//obj不能可选为空,数据会被线程冲刷,需要传递原有数据
8384
{
84-
lock (_toExecuteQueue)
85+
lock (_locker)
8586
{
8687
_toExecuteQueue.Enqueue(new ToExecute(action, obj));
8788
}

0 commit comments

Comments
 (0)