Tried to fix possible error/crash when loading bad time codes - thx Jucá :)

This commit is contained in:
niksedk 2014-04-07 13:44:34 +02:00
parent a2d4e20b32
commit 9723ae4d3c
2 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,6 @@
using System; using Nikse.SubtitleEdit.Logic;
using System;
using System.Windows.Forms; using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Controls namespace Nikse.SubtitleEdit.Controls
{ {
@ -53,7 +53,7 @@ namespace Nikse.SubtitleEdit.Controls
double? millisecs = GetTotalMilliseconds(); double? millisecs = GetTotalMilliseconds();
if (millisecs.HasValue) if (millisecs.HasValue)
{ {
if (millisecs.Value == TimeCode.MaxTime.TotalMilliseconds) if (millisecs.Value >= TimeCode.MaxTime.TotalMilliseconds - 0.1)
millisecs = 0; millisecs = 0;
if (Mode == TimeMode.HHMMSSMS) if (Mode == TimeMode.HHMMSSMS)
@ -194,7 +194,7 @@ namespace Nikse.SubtitleEdit.Controls
} }
set set
{ {
if (value.TotalMilliseconds == TimeCode.MaxTime.TotalMilliseconds) if (value.TotalMilliseconds >= TimeCode.MaxTime.TotalMilliseconds - 0.1)
{ {
maskedTextBox1.Text = string.Empty; maskedTextBox1.Text = string.Empty;
return; return;

View File

@ -8082,14 +8082,20 @@ namespace Nikse.SubtitleEdit.Forms
if (Configuration.Settings.General.UseTimeFormatHHMMSSFF) if (Configuration.Settings.General.UseTimeFormatHHMMSSFF)
{ {
int wholeSeconds = (int)seconds; int wholeSeconds = (int)seconds;
int frames = SubtitleFormat.MillisecondsToFrames(seconds % 1.0 * 1000); int frames = SubtitleFormat.MillisecondsToFrames(seconds % 1.0 * 1000.0);
int extraSeconds = (int)(frames / Configuration.Settings.General.CurrentFrameRate); int extraSeconds = (int)(frames / Configuration.Settings.General.CurrentFrameRate);
int restFrames = (int)(frames % Configuration.Settings.General.CurrentFrameRate); int restFrames = (int)(frames % Configuration.Settings.General.CurrentFrameRate);
numericUpDownDuration.Value = (decimal)(wholeSeconds + extraSeconds + restFrames / 100.0); numericUpDownDuration.Value = (decimal)(wholeSeconds + extraSeconds + restFrames / 100.0);
} }
else else
{ {
numericUpDownDuration.Value = (decimal)seconds; var d = (decimal) seconds;
if (d > numericUpDownDuration.Maximum)
numericUpDownDuration.Value = numericUpDownDuration.Maximum;
else if (d < numericUpDownDuration.Minimum)
numericUpDownDuration.Value = numericUpDownDuration.Minimum;
else
numericUpDownDuration.Value = d;
} }
} }