Skip to content

Commit

Permalink
fix: github windows workflow PortAudio load crash (#717)
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilien Noal <noal.maximilien@gmail.com>
  • Loading branch information
maximilien-noal authored Jun 8, 2024
1 parent 71842eb commit bc9549c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Spice86.Core/Backend/Audio/PortAudio/PortAudioPlayerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ public class PortAudioPlayerFactory {
private PortAudioLib LoadPortAudioLibrary() {
if (OperatingSystem.IsWindows() && Environment.Is64BitOperatingSystem) {
const string path = "libportaudio.dll";
return new PortAudioLib(path);
} else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS() || OperatingSystem.IsWindows()) {
if (File.Exists(path)) {
return new PortAudioLib(path);
}
}

if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) {
//rely on system-provided libportaudio.
return new PortAudioLib();
} else {
throw new PlatformNotSupportedException();
}

throw new PlatformNotSupportedException();
}

/// <summary>
Expand All @@ -49,11 +53,14 @@ private PortAudioLib LoadPortAudioLibrary() {
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(e, "The native PortAudio library could not be loaded");
}
}
catch (BufdioException e) {
} catch (BufdioException e) {
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(e, "No audio output device could be found");
}
} catch (PlatformNotSupportedException e) {
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(e, "A compatible PortAudio library could not be found for the current platform");
}
}
}
return null;
Expand Down

0 comments on commit bc9549c

Please sign in to comment.