Skip to content

Commit

Permalink
Fix crash during performance point calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
matte-ek committed May 12, 2023
1 parent 1c24658 commit bf7ad85
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions BanchoMultiplayerBot/OsuApi/PerformancePointCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public class PerformancePointCalculator
{
var performanceCalcProcess = RunProcessAsync($"performance-calculator", $"{beatmapId}");

if (performanceCalcProcess == null)
{
return null;
}

try
{
string output = await performanceCalcProcess.WaitAsync(TimeSpan.FromSeconds(5));
Expand Down Expand Up @@ -109,32 +114,47 @@ public class PerformancePointCalculator
/// Returns a task to run a process asynchronously, end result is STDOUT.
/// This should be use with caution, make sure no weird user input is sent.
/// </summary>
private Task<string> RunProcessAsync(string cmd, string arguments)
private Task<string>? RunProcessAsync(string cmd, string arguments)
{
var taskCompletionSource = new TaskCompletionSource<string>();

var process = new Process
try
{
StartInfo =
var taskCompletionSource = new TaskCompletionSource<string>();

var process = new Process
{
FileName = cmd,
Arguments = arguments,
RedirectStandardOutput = true,
},
EnableRaisingEvents = true
};
StartInfo =
{
FileName = cmd,
Arguments = arguments,
RedirectStandardOutput = true,
},
EnableRaisingEvents = true
};

process.Exited += (sender, args) =>
{
string stdOut = process.StandardOutput.ReadToEnd();
process.Exited += (sender, args) =>
{
try
{
string stdOut = process.StandardOutput.ReadToEnd();

taskCompletionSource.SetResult(stdOut);
taskCompletionSource.SetResult(stdOut);

process.Dispose();
};
process.Dispose();
}
catch (Exception e)
{
// ignored
}
};

process.Start();
process.Start();

return taskCompletionSource.Task;
return taskCompletionSource.Task;
}
catch (Exception e)
{
Log.Error($"Exception at RunProcessAsync: {e}");
return null;
}
}
}

0 comments on commit bf7ad85

Please sign in to comment.