From e091b30707c83b6cbd483e8cb673394c9e1c3452 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Wed, 4 Mar 2020 16:05:16 +0100 Subject: [PATCH] Fix "Batch convert" issue with new auto-br optimzation --- libse/TextSplitResult.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libse/TextSplitResult.cs b/libse/TextSplitResult.cs index 2788332e0..219b6e6c1 100644 --- a/libse/TextSplitResult.cs +++ b/libse/TextSplitResult.cs @@ -17,6 +17,7 @@ namespace Nikse.SubtitleEdit.Core private static readonly Graphics Graphics = Graphics.FromHwnd(IntPtr.Zero); private static readonly Font DefaultFont = SystemFonts.DefaultFont; + private static readonly object GdiLock = new object(); public TextSplitResult(List lines) { @@ -24,15 +25,24 @@ namespace Nikse.SubtitleEdit.Core LengthPixels = new List(); if (Configuration.Settings.Tools.AutoBreakUsePixelWidth) { - var lineOneWidth = Graphics.MeasureString(Lines[0], DefaultFont).Width; - LengthPixels.Add(lineOneWidth); + lock (GdiLock) + { + var lineOneWidth = Graphics.MeasureString(Lines[0], DefaultFont).Width; + LengthPixels.Add(lineOneWidth); + } - var lineTwoWidth = Graphics.MeasureString(Lines[1], DefaultFont).Width; - LengthPixels.Add(lineTwoWidth); + lock (GdiLock) + { + var lineTwoWidth = Graphics.MeasureString(Lines[1], DefaultFont).Width; + LengthPixels.Add(lineTwoWidth); + } if (Math.Abs(SpaceLengthPixels) < 0.01) { - SpaceLengthPixels = Graphics.MeasureString(" ", DefaultFont).Width; + lock (GdiLock) + { + SpaceLengthPixels = Graphics.MeasureString(" ", DefaultFont).Width; + } } }