Skip to content

Commit af7565f

Browse files
committed
Better handling of error handling during crashes
1 parent 03b4f44 commit af7565f

9 files changed

Lines changed: 53 additions & 9 deletions

File tree

AudioPlugSharp/AudioPlugSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Library</OutputType>
6-
<Version>0.7.3</Version>
6+
<Version>0.7.4</Version>
77
<Authors>Mike Oliphant</Authors>
88
<Description>Easily create VST (VST3) audio plugins in C# .NET.</Description>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>

AudioPlugSharp/Logger.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class Logger
2222
static StreamWriter logWriter = null;
2323
static string logPath;
2424
static string logFileDateFormat = "yyyy-MM-dd-HH-mm-ss-ffff";
25+
static Thread logThread;
26+
static bool exit = false;
2527

2628
static Logger()
2729
{
@@ -51,7 +53,7 @@ static Logger()
5153

5254
logWriter = new StreamWriter(logFile);
5355

54-
Thread logThread = new Thread(() => DoLogging());
56+
logThread = new Thread(() => DoLogging());
5557

5658
logThread.Priority = ThreadPriority.Lowest;
5759
logThread.IsBackground = true;
@@ -118,6 +120,9 @@ static void DoLogging()
118120
{
119121
WriteLogs();
120122
}
123+
124+
if (exit)
125+
break;
121126
}
122127
while (true);
123128
}
@@ -147,5 +152,15 @@ static void WriteLogs()
147152
catch { }
148153
}
149154
}
155+
156+
public static void FlushAndShutdown()
157+
{
158+
exit = true;
159+
160+
if (logThread != null)
161+
logThread.Join();
162+
163+
logThread = null;
164+
}
150165
}
151166
}

AudioPlugSharpHost/AudioPlugSharpHost.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
88
<UseWindowsForms>true</UseWindowsForms>
9-
<Version>0.7.0</Version>
9+
<Version>0.7.4</Version>
1010
<Authors>Mike Oliphant</Authors>
1111
<Description>Stand-alone ASIO host for AudioPlugSharp plugins.</Description>
1212
<PackageLicenseExpression>MIT</PackageLicenseExpression>

AudioPlugSharpHost/WindowsFormsHost.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,27 @@ public void Run()
3232
if (audioHost.AsioDriver == null)
3333
ShowAudioSettings();
3434

35-
audioHost.Plugin.ShowEditor(IntPtr.Zero);
35+
if (Plugin.HasUserInterface)
36+
{
37+
try
38+
{
39+
Plugin.ShowEditor(IntPtr.Zero);
40+
}
41+
catch (Exception ex)
42+
{
43+
Logger.Log("Plugin failed with: " + ex.ToString());
44+
}
45+
}
46+
else
47+
{
48+
Thread.Sleep(Timeout.Infinite);
49+
}
50+
3651
audioHost.Exit();
3752

3853
notifyIcon.Visible = false;
54+
55+
Logger.FlushAndShutdown();
3956
}
4057

4158
void ShowAudioSettings()

AudioPlugSharpJack/AudioPlugSharpJack.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>0.7.0</Version>
7+
<Version>0.7.4</Version>
88
<Authors>Mike Oliphant</Authors>
99
<Description>Jack Audio host for AudioPlugSharp plugins.</Description>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>

AudioPlugSharpJack/JackHost.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,23 @@ public void Run()
110110

111111
if (Plugin.HasUserInterface)
112112
{
113-
Plugin.ShowEditor(IntPtr.Zero);
113+
try
114+
{
115+
Plugin.ShowEditor(IntPtr.Zero);
116+
}
117+
catch (Exception ex)
118+
{
119+
Logger.Log("Plugin failed with: " + ex.ToString());
120+
}
114121

115122
Exit();
116123
}
117124
else
118125
{
119126
Thread.Sleep(Timeout.Infinite);
120127
}
128+
129+
Logger.FlushAndShutdown();
121130
}
122131
}
123132

AudioPlugSharpVst3/AudioPlugSharpVst3.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>0.7.3</Version>
7+
<Version>0.7.4</Version>
88
<Authors>Mike Oliphant</Authors>
99
<Description>AudioPlugSharp VST3 plugin implmentation</Description>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>

AudioPlugSharpWPF/AudioPlugSharpWPF.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0-windows</TargetFramework>
55
<UseWPF>true</UseWPF>
66
<UseWindowsForms>true</UseWindowsForms>
7-
<Version>0.7.3</Version>
7+
<Version>0.7.4</Version>
88
<Authors>Mike Oliphant</Authors>
99
<Description>Add WPF GUI to your AudioPlugSharp plugin.</Description>
1010
<PackageLicenseExpression>MIT</PackageLicenseExpression>

JackHostTest/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using AudioPlugSharpJack;
1+
using AudioPlugSharp;
2+
using AudioPlugSharpJack;
23
using SimpleExample;
34

45
namespace JackHostTest
@@ -10,6 +11,8 @@ static void Main(string[] args)
1011
JackHost<SimpleExamplePlugin> host = new JackHost<SimpleExamplePlugin>(new SimpleExamplePlugin());
1112

1213
host.Run();
14+
15+
Logger.FlushAndShutdown();
1316
}
1417
}
1518
}

0 commit comments

Comments
 (0)