Merge pull request #1166 from CoderCow/general-devel

Concurrent Dictionary Access Fix
This commit is contained in:
Tyler Watson 2016-02-29 09:02:28 +10:00
commit fc69dccb8b
2 changed files with 15 additions and 9 deletions

View file

@ -2137,8 +2137,9 @@ namespace TShockAPI
{ {
args.Player.TilePlaceThreshold++; args.Player.TilePlaceThreshold++;
var coords = new Vector2(tileX, tileY); var coords = new Vector2(tileX, tileY);
if (!args.Player.TilesCreated.ContainsKey(coords)) lock (args.Player.TilesCreated)
args.Player.TilesCreated.Add(coords, Main.tile[tileX, tileY]); if (!args.Player.TilesCreated.ContainsKey(coords))
args.Player.TilesCreated.Add(coords, Main.tile[tileX, tileY]);
} }
if ((action == EditAction.KillTile || action == EditAction.KillTileNoItem || action == EditAction.KillWall) && Main.tileSolid[Main.tile[tileX, tileY].type] && if ((action == EditAction.KillTile || action == EditAction.KillTileNoItem || action == EditAction.KillWall) && Main.tileSolid[Main.tile[tileX, tileY].type] &&
@ -2146,8 +2147,9 @@ namespace TShockAPI
{ {
args.Player.TileKillThreshold++; args.Player.TileKillThreshold++;
var coords = new Vector2(tileX, tileY); var coords = new Vector2(tileX, tileY);
if (!args.Player.TilesDestroyed.ContainsKey(coords)) lock (args.Player.TilesDestroyed)
args.Player.TilesDestroyed.Add(coords, Main.tile[tileX, tileY]); if (!args.Player.TilesDestroyed.ContainsKey(coords))
args.Player.TilesDestroyed.Add(coords, Main.tile[tileX, tileY]);
} }
return false; return false;
} }
@ -2239,8 +2241,9 @@ namespace TShockAPI
{ {
args.Player.TilePlaceThreshold++; args.Player.TilePlaceThreshold++;
var coords = new Vector2(x, y); var coords = new Vector2(x, y);
if (!args.Player.TilesCreated.ContainsKey(coords)) lock (args.Player.TilesCreated)
args.Player.TilesCreated.Add(coords, Main.tile[x, y]); if (!args.Player.TilesCreated.ContainsKey(coords))
args.Player.TilesCreated.Add(coords, Main.tile[x, y]);
} }
return false; return false;

View file

@ -894,7 +894,8 @@ namespace TShockAPI
{ {
player.TileKillThreshold = 0; player.TileKillThreshold = 0;
//We don't want to revert the entire map in case of a disable. //We don't want to revert the entire map in case of a disable.
player.TilesDestroyed.Clear(); lock (player.TilesDestroyed)
player.TilesDestroyed.Clear();
} }
if (player.TilesCreated != null) if (player.TilesCreated != null)
@ -902,8 +903,10 @@ namespace TShockAPI
if (player.TilePlaceThreshold >= Config.TilePlaceThreshold) if (player.TilePlaceThreshold >= Config.TilePlaceThreshold)
{ {
player.Disable("Reached TilePlace threshold", flags); player.Disable("Reached TilePlace threshold", flags);
TSPlayer.Server.RevertTiles(player.TilesCreated); lock (player.TilesCreated) {
player.TilesCreated.Clear(); TSPlayer.Server.RevertTiles(player.TilesCreated);
player.TilesCreated.Clear();
}
} }
} }
if (player.TilePlaceThreshold > 0) if (player.TilePlaceThreshold > 0)