Skip to content

Commit

Permalink
Catch DllNotFound exceptions on VulkanTest on Waifu2X
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Oct 22, 2024
1 parent 80493bb commit 0f4922a
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions CollapseLauncher/Classes/Helper/Image/Waifu2X.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,30 +202,48 @@ public int GetParam(Param param)
#region Misc
public static Waifu2XStatus VulkanTest()
{
if (CheckD3DMappingLayersPackageInstalled())
try
{
if (CheckD3DMappingLayersPackageInstalled())
{
Logger.LogWriteLine("D3DMappingLayers package detected. Fallback to CPU mode.", LogType.Warning, true);
return Waifu2XStatus.D3DMappingLayers;
}
var status = waifu2x_self_test(0);
switch (status)
{
case Waifu2XStatus.CpuMode:
Logger.LogWriteLine("No available Vulkan GPU device was found and CPU mode will be used. This will greatly increase image processing time.", LogType.Warning, true);
break;
case Waifu2XStatus.NotAvailable:
Logger.LogWriteLine("An error occurred while initializing Vulkan. Fallback to CPU mode.", LogType.Warning, true);
status = Waifu2XStatus.CpuMode;
break;
case Waifu2XStatus.Ok:
Logger.LogWriteLine("Vulkan test passes and GPU mode can be used.", LogType.Default, true);
break;
default:
Logger.LogWriteLine("Waifu2X: Unknown return value from waifu2x_self_test.", LogType.Error, true);
status = Waifu2XStatus.NotAvailable;
break;
}
return status;
}
catch (FileLoadException ex)
{
return ReturnAsFailedDllInit(ex);
}
catch (DllNotFoundException ex)
{
Logger.LogWriteLine("D3DMappingLayers package detected. Fallback to CPU mode.", LogType.Warning, true);
return Waifu2XStatus.D3DMappingLayers;
return ReturnAsFailedDllInit(ex);
}
var status = waifu2x_self_test(0);
switch (status)

Waifu2XStatus ReturnAsFailedDllInit<T>(T ex)
where T : Exception
{
case Waifu2XStatus.CpuMode:
Logger.LogWriteLine("No available Vulkan GPU device was found and CPU mode will be used. This will greatly increase image processing time.", LogType.Warning, true);
break;
case Waifu2XStatus.NotAvailable:
Logger.LogWriteLine("An error occurred while initializing Vulkan. Fallback to CPU mode.", LogType.Warning, true);
status = Waifu2XStatus.CpuMode;
break;
case Waifu2XStatus.Ok:
Logger.LogWriteLine("Vulkan test passes and GPU mode can be used.", LogType.Default, true);
break;
default:
Logger.LogWriteLine("Waifu2X: Unknown return value from waifu2x_self_test.", LogType.Error, true);
status = Waifu2XStatus.NotAvailable;
break;
Logger.LogWriteLine($"Cannot load Waifu2X as the library failed to load!\r\n{ex}", LogType.Error, true);
return Waifu2XStatus.Error;
}
return status;
}

private bool ProcessTest()
Expand Down

0 comments on commit 0f4922a

Please sign in to comment.