(9d3dd6da9) Reattempt decompressing saves files and initiating file transfers a few times before throwing an error. Running multiple instances of the game from the same install (or hosting a server as a client) occasionally causes IOExceptions because the instances try to access the same files.

This commit is contained in:
Joonas Rikkonen
2019-03-25 19:51:39 +02:00
parent 006d53ccf1
commit 86c4b6a3ae
3 changed files with 80 additions and 22 deletions
@@ -1,8 +1,10 @@
using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
namespace Barotrauma.Networking
{
@@ -76,8 +78,21 @@ namespace Barotrauma.Networking
Status = FileTransferStatus.NotStarted;
startingTime = DateTime.Now;
data = File.ReadAllBytes(filePath);
int maxRetries = 4;
for (int i = 0; i <= maxRetries; i++)
{
try
{
data = File.ReadAllBytes(filePath);
}
catch (IOException e)
{
if (i >= maxRetries) { throw; }
DebugConsole.NewMessage("Failed to initiate a file transfer {" + e.Message + "}, retrying in 250 ms...", Color.Red);
Thread.Sleep(250);
}
}
}
}