From a283b2d1b9a26057f6c3c995e498610d72d714b0 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 5 Aug 2015 16:37:17 -0500 Subject: [PATCH] fix threading bug in movie scanner --- BizHawk.Client.EmuHawk/movie/PlayMovie.cs | 37 ++++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index 64b15abcab..83e7d91f46 100644 --- a/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -87,26 +87,27 @@ namespace BizHawk.Client.EmuHawk return null; } - var index = IsDuplicateOf(filename); - if (!index.HasValue) + //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); + var movie = PreLoadMovieFile(file, force); + if (movie == null) { - //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); - var movie = PreLoadMovieFile(file, force); - if (movie == null) - { - return null; - } - //watch.Stop(); Console.WriteLine("[{0}] {1}",watch.ElapsedMilliseconds,Path.GetFileName(filename)); - - lock (_movieList) - { - _movieList.Add(movie); - index = _movieList.Count - 1; - } - - _sortReverse = false; - _sortedCol = string.Empty; + return null; } + //watch.Stop(); Console.WriteLine("[{0}] {1}",watch.ElapsedMilliseconds,Path.GetFileName(filename)); + + int? index; + lock (_movieList) + { + //need to check IsDuplicateOf within the lock + index = IsDuplicateOf(filename); + if (index.HasValue) return index; + + _movieList.Add(movie); + index = _movieList.Count - 1; + } + + _sortReverse = false; + _sortedCol = string.Empty; return index; }