Fix crash due to unkilled WebView2 instances.

This commit is contained in:
Chax
2023-11-16 21:18:47 +01:00
parent ecf19115c6
commit b4fd4c76a0
2 changed files with 31 additions and 0 deletions

View File

@@ -3081,6 +3081,7 @@ Things you can try:
}
else
{
if (!Properties.Settings.Default.TrailersOn) { Sideloader.killWebView2(); }
RCLONE.killRclone();
}
}
@@ -3095,12 +3096,14 @@ Things you can try:
}
else
{
if (!Properties.Settings.Default.TrailersOn) { Sideloader.killWebView2(); }
RCLONE.killRclone();
_ = ADB.RunAdbCommandToString("kill-server");
}
}
else
{
if (!Properties.Settings.Default.TrailersOn) { Sideloader.killWebView2(); }
RCLONE.killRclone();
_ = ADB.RunAdbCommandToString("kill-server");
}

View File

@@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
@@ -13,6 +14,33 @@ namespace AndroidSideloader
public static string TempFolder = Path.Combine(Environment.CurrentDirectory, "temp");
public static string CrashLogPath = "crashlog.txt";
public static void killWebView2()
{
var parentProcessId = Process.GetCurrentProcess().Id;
var processes = Process.GetProcessesByName("msedgewebview2");
foreach (var process in processes)
{
try
{
using (ManagementObject obj = new ManagementObject($"win32_process.handle='{process.Id}'"))
{
obj.Get();
var ppid = Convert.ToInt32(obj["ParentProcessId"]);
if (ppid == parentProcessId)
{
process.Kill();
}
}
}
catch (Exception ex)
{
_ = Logger.Log($"Exception occured while attempting to shut down WebView2 with exception message: {ex.Message}", LogLevel.ERROR);
}
}
}
//push user.json to device (required for some devices like oculus quest)
public static void PushUserJsons()
{