From a883f4611db52230835b388dda1d20b38a999daf Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 15 Jun 2018 19:51:24 +0100 Subject: [PATCH] WinGui: Fix a potential crash in HandBrakeEncoderHelpers.cs --- .../Interop/HandBrakeEncoderHelpers.cs | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs index db5744315..f684d7367 100644 --- a/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs +++ b/win/CS/HandBrake.Interop/Interop/HandBrakeEncoderHelpers.cs @@ -244,15 +244,15 @@ namespace HandBrake.Interop.Interop return Mixdowns.SingleOrDefault(m => m.ShortName == shortName); } - /// - /// Gets the mixdown with the specified ID. - /// - /// The mixdown ID. - /// The requested mixdown. - public static HBMixdown GetMixdown(int id) - { - return Mixdowns.SingleOrDefault(m => m.Id == id); - } + /// + /// Gets the mixdown with the specified ID. + /// + /// The mixdown ID. + /// The requested mixdown. + public static HBMixdown GetMixdown(int id) + { + return Mixdowns.SingleOrDefault(m => m.Id == id); + } /// /// Gets the container with the specified short name. @@ -468,7 +468,7 @@ namespace HandBrake.Interop.Interop /// public static HBMixdown SanitizeMixdown(HBMixdown mixdown, HBAudioEncoder encoder, ulong layout) { - if (mixdown == null) + if (mixdown == null || encoder == null) { return null; } @@ -478,6 +478,7 @@ namespace HandBrake.Interop.Interop { return Mixdowns.Single(m => m.Id == sanitizedMixdown); } + return Mixdowns.FirstOrDefault(); // "none" } @@ -499,16 +500,16 @@ namespace HandBrake.Interop.Interop return Mixdowns.Single(m => m.Id == defaultMixdown); } - /// - /// Sanitizes the given sample rate for the given encoder. - /// - /// The encoder. - /// The sample rate to sanitize. - /// The sanitized sample rate. - public static int SanitizeSampleRate(HBAudioEncoder encoder, int sampleRate) - { - return HBFunctions.hb_audio_samplerate_find_closest(sampleRate, (uint)encoder.Id); - } + /// + /// Sanitizes the given sample rate for the given encoder. + /// + /// The encoder. + /// The sample rate to sanitize. + /// The sanitized sample rate. + public static int SanitizeSampleRate(HBAudioEncoder encoder, int sampleRate) + { + return HBFunctions.hb_audio_samplerate_find_closest(sampleRate, (uint)encoder.Id); + } /// /// Gets the bitrate limits for the given audio codec, sample rate and mixdown. -- 2.40.0