From: sr55 Date: Fri, 15 Jun 2018 18:51:24 +0000 (+0100) Subject: WinGui: Fix a potential crash in HandBrakeEncoderHelpers.cs X-Git-Tag: 1.2.0~309 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a883f4611db52230835b388dda1d20b38a999daf;p=handbrake WinGui: Fix a potential crash in HandBrakeEncoderHelpers.cs --- 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.