mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Ensure proper thread safety when adding to the block queue.
This commit is contained in:
parent
ffad2edc72
commit
408c80a0df
@ -33,8 +33,10 @@ namespace MCGalaxy.Commands {
|
||||
string cmd = args[0].ToLower();
|
||||
if (cmd == "clear") {
|
||||
Level[] loaded = LevelInfo.Loaded.Items;
|
||||
foreach (Level lvl in loaded)
|
||||
lvl.blockqueue.Clear();
|
||||
foreach (Level lvl in loaded) {
|
||||
lock (lvl.queueLock)
|
||||
lvl.blockqueue.Clear();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (args.Length == 1) { Help(p); return; }
|
||||
|
@ -41,11 +41,9 @@ namespace MCGalaxy.Commands
|
||||
p.isFlying = false;
|
||||
p.BrushName = "normal";
|
||||
p.DefaultBrushArgs = "";
|
||||
try
|
||||
{
|
||||
|
||||
lock (p.level.queueLock)
|
||||
p.level.blockqueue.RemoveAll(b => b.p == p);
|
||||
}
|
||||
finally { BlockQueue.Resume(); }
|
||||
Player.Message(p, "Every toggle or action was aborted.");
|
||||
}
|
||||
public override void Help(Player p)
|
||||
|
@ -32,8 +32,10 @@ namespace MCGalaxy {
|
||||
started = true;
|
||||
try {
|
||||
Level[] loaded = LevelInfo.Loaded.Items;
|
||||
foreach (Level l in loaded)
|
||||
ProcessLevelBlocks(l);
|
||||
foreach (Level lvl in loaded) {
|
||||
lock (lvl.queueLock)
|
||||
ProcessLevelBlocks(lvl);
|
||||
}
|
||||
bulkSender.level = null;
|
||||
} catch (Exception ex) {
|
||||
Server.ErrorLog(ex);
|
||||
@ -53,7 +55,8 @@ namespace MCGalaxy {
|
||||
block item;
|
||||
item.p = p; item.index = index;
|
||||
item.type = type; item.extType = extType;
|
||||
p.level.blockqueue.Add(item);
|
||||
lock (p.level.queueLock)
|
||||
p.level.blockqueue.Add(item);
|
||||
}
|
||||
|
||||
static void ProcessLevelBlocks(Level lvl) {
|
||||
@ -67,7 +70,7 @@ namespace MCGalaxy {
|
||||
for (int c = 0; c < count; c++) {
|
||||
block item = lvl.blockqueue[c];
|
||||
bulkSender.Add(item.index, item.type, item.extType);
|
||||
bulkSender.CheckIfSend(false);
|
||||
bulkSender.CheckIfSend(false);
|
||||
}
|
||||
bulkSender.CheckIfSend(true);
|
||||
lvl.blockqueue.RemoveRange(0, count);
|
||||
|
@ -236,7 +236,9 @@ namespace MCGalaxy
|
||||
public bool unload = true;
|
||||
[ConfigBool("WorldChat", "General", null, true)]
|
||||
public bool worldChat = true;
|
||||
|
||||
public bool bufferblocks = Server.bufferblocks;
|
||||
internal readonly object queueLock = new object();
|
||||
public List<BlockQueue.block> blockqueue = new List<BlockQueue.block>();
|
||||
private readonly object physThreadLock = new object();
|
||||
BufferedBlockSender bulkSender;
|
||||
@ -331,7 +333,8 @@ namespace MCGalaxy
|
||||
UndoBuffer.Clear();
|
||||
blockCache.Clear();
|
||||
ZoneList.Clear();
|
||||
blockqueue.Clear();
|
||||
lock (queueLock)
|
||||
blockqueue.Clear();
|
||||
blocks = null;
|
||||
CustomBlocks = null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user