From d94868f4660c092bc24ee4e1ceeccc1e7aa48dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 7 Sep 2017 16:56:31 +0200 Subject: [PATCH 01/14] Fixed drawing non-latin character not correctly, closes #310 --- Vocaluxe/Base/CCoverGenerator.cs | 4 ++-- Vocaluxe/Base/Fonts/CGlyph.cs | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Base/CCoverGenerator.cs b/Vocaluxe/Base/CCoverGenerator.cs index 1ff20fa9..39034d1b 100644 --- a/Vocaluxe/Base/CCoverGenerator.cs +++ b/Vocaluxe/Base/CCoverGenerator.cs @@ -84,7 +84,7 @@ namespace Vocaluxe.Base if (_WidthTrimmed < 0f) { string text = Text.TrimEnd(null); - _WidthTrimmed = text.Length == Text.Length ? Width : _Graphics.MeasureString(text, _Font, -1, StringFormat.GenericTypographic).Width; + _WidthTrimmed = text.Length == Text.Length ? Width : _Graphics.MeasureString(text, _Font).Width; } return _WidthTrimmed; } @@ -94,7 +94,7 @@ namespace Vocaluxe.Base public CTextElement(string text, Graphics g, Font font) { Text = text; - SizeF dimensions = g.MeasureString(text, font, -1, StringFormat.GenericTypographic); + SizeF dimensions = g.MeasureString(text, font); Width = dimensions.Width; Height = (dimensions.Height + font.Height) / 2; _Graphics = g; diff --git a/Vocaluxe/Base/Fonts/CGlyph.cs b/Vocaluxe/Base/Fonts/CGlyph.cs index 6b949903..f9bc02ed 100644 --- a/Vocaluxe/Base/Fonts/CGlyph.cs +++ b/Vocaluxe/Base/Fonts/CGlyph.cs @@ -51,7 +51,13 @@ namespace Vocaluxe.Base.Fonts if (chr != ' ') { //Gets exact height and width for drawing more than 1 char. But width is to small to draw char on bitmap as e.g. italic chars will get cropped - _BoundingBox = g.MeasureString(chrString, fo, -1, StringFormat.GenericTypographic); + //See https://stackoverflow.com/questions/11708621/how-to-measure-width-of-a-string-precisely + StringFormat format = StringFormat.GenericTypographic; + RectangleF rect = new RectangleF(0, 0, 1000, 1000); + CharacterRange[] ranges = { new CharacterRange(0, chrString.Length) }; + format.SetMeasurableCharacterRanges(ranges); + _BoundingBox = g.MeasureCharacterRanges(chrString, fo, rect, format)[0].GetBounds(g).Size; + // ReSharper disable CompareOfFloatsByEqualityOperator if (_BoundingBox.Height == 0) // ReSharper restore CompareOfFloatsByEqualityOperator From 41cf7a5ac2572f3198c6886ef2871fbd35f65375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 28 Sep 2017 17:31:16 +0200 Subject: [PATCH 02/14] push to trigger appveyor From 4784e57370ae272a445666d89b5915644cd8de7a Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Wed, 4 Oct 2017 13:12:14 +0200 Subject: [PATCH 03/14] Refactored mutex use while closing streams in CPortAudioHandle (should fix #320) --- Vocaluxe/Lib/Sound/CPortAudioHandle.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs index 217afafa..6443a8cb 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs @@ -74,12 +74,14 @@ namespace Vocaluxe.Lib.Sound } lock (_Mutex) { + if (_Disposed) + return; Debug.Assert(_RefCount > 0); _RefCount--; if (_RefCount == 0) PortAudio.Pa_Terminate(); + _Disposed = true; } - _Disposed = true; } public void Dispose() @@ -100,11 +102,11 @@ namespace Vocaluxe.Lib.Sound double sampleRate, uint framesPerBuffer, PortAudio.PaStreamFlags streamFlags, PortAudio.PaStreamCallbackDelegate streamCallback, IntPtr userData) { - if (_Disposed) - throw new ObjectDisposedException("PortAudioHandle already disposed"); - lock (_Mutex) { + if (_Disposed) + throw new ObjectDisposedException("PortAudioHandle already disposed"); + PortAudio.PaError res = PortAudio.Pa_OpenStream(out stream, ref inputParameters, ref outputParameters, sampleRate, framesPerBuffer, streamFlags, streamCallback, userData); if (res == PortAudio.PaError.paNoError) @@ -157,11 +159,11 @@ namespace Vocaluxe.Lib.Sound public void CloseStream(IntPtr stream) { - if (_Disposed) - throw new ObjectDisposedException("PortAudioHandle already disposed"); - lock (_Mutex) { + if (_Disposed) + throw new ObjectDisposedException("PortAudioHandle already disposed"); + PortAudio.Pa_CloseStream(stream); _Streams.Remove(stream); } From ad5ffd7578736cfe45b0a9dc5bfa94ecc44dc46f Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Wed, 4 Oct 2017 14:20:31 +0200 Subject: [PATCH 04/14] Catch potential errors from PortAudio Close() and Dispose() --- Vocaluxe/Lib/Sound/CPortAudioHandle.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs index 6443a8cb..81c4d9b0 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioHandle.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioHandle.cs @@ -79,7 +79,16 @@ namespace Vocaluxe.Lib.Sound Debug.Assert(_RefCount > 0); _RefCount--; if (_RefCount == 0) - PortAudio.Pa_Terminate(); + { + try + { + PortAudio.Pa_Terminate(); + } + catch (Exception ex) + { + CLog.LogError(errorText: $"Error disposing PortAudio: {ex.Message}", e: ex); + } + } _Disposed = true; } } @@ -164,7 +173,14 @@ namespace Vocaluxe.Lib.Sound if (_Disposed) throw new ObjectDisposedException("PortAudioHandle already disposed"); - PortAudio.Pa_CloseStream(stream); + try + { + PortAudio.Pa_CloseStream(stream); + } + catch (Exception ex) + { + CLog.LogError(errorText:$"Error closing stream: {ex.Message}", e:ex); + } _Streams.Remove(stream); } } From df34766f353cef0ece17bedf5677cb81dd5d967f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:40:59 +0200 Subject: [PATCH 05/14] Fixed aspect of avatars --- PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs | 1 + PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs | 3 +++ Vocaluxe/Screens/CScreenScore.cs | 3 +++ VocaluxeLib/Menu/CSelectSlide.cs | 1 + 4 files changed, 8 insertions(+) diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs index 5e10bcff..77a5eb88 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs @@ -125,6 +125,7 @@ namespace VocaluxeLib.PartyModes.Challenge _AddText(_NextPlayerTexts[_NextPlayerTexts.Count - 1]); _NextPlayerStatics.Add(GetNewStatic(_Statics[_StaticNextPlayer])); _AddStatic(_NextPlayerStatics[_NextPlayerStatics.Count - 1]); + _NextPlayerStatics[_NextPlayerStatics.Count - 1].Aspect = EAspect.Crop; } _Statics[_StaticNextPlayer].Visible = false; } diff --git a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs index 35f45351..0588abeb 100644 --- a/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs +++ b/PartyModes/PartyModeTicTacToe/CPartyScreenTicTacToeMain.cs @@ -98,6 +98,9 @@ namespace VocaluxeLib.PartyModes.TicTacToe _CreateFields(); _Buttons[_ButtonField].Visible = false; + + _Statics[_StaticAvatarT1].Aspect = EAspect.Crop; + _Statics[_StaticAvatarT2].Aspect = EAspect.Crop; } public override bool HandleInput(SKeyEvent keyEvent) diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index 2f4f564a..249198ef 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -139,6 +139,9 @@ namespace Vocaluxe.Screens _SetVisibility(); _UpdateRatings(); _SlideShowBG.Visible = _UpdateBackground(); + + for (int p = 0; p < CGame.NumPlayers; p++) + _Statics[_StaticAvatar[p, CGame.NumPlayers - 1]].Aspect = EAspect.Crop; } public override bool UpdateGame() diff --git a/VocaluxeLib/Menu/CSelectSlide.cs b/VocaluxeLib/Menu/CSelectSlide.cs index fa6310b2..f9fef6a2 100644 --- a/VocaluxeLib/Menu/CSelectSlide.cs +++ b/VocaluxeLib/Menu/CSelectSlide.cs @@ -586,6 +586,7 @@ namespace VocaluxeLib.Menu Text = new CText(0, 0, 0, _TextH, _MaxW, EAlignment.Center, _Theme.TextStyle, _Theme.TextFont, _TextColor, "T", _PartyModeID), Img = new CStatic(_PartyModeID) }; + el.Img.Aspect = EAspect.Crop; _VisibleElements.Add(el); } } From 85ad6050f80f9c125d08ebdef1dc0f0c3ef16dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:56:16 +0200 Subject: [PATCH 06/14] Fixed lyrics visibility (closes #322) --- Vocaluxe/Screens/CScreenSing.cs | 49 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 7bf7e042..c082e1bd 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -611,35 +611,38 @@ namespace Vocaluxe.Screens private void _SetDuetLyricsVisibility(bool isDuet) { - _Statics[_StaticLyricsDuet].Visible = isDuet; - _Lyrics[_LyricMainDuet].Visible = isDuet; - _Lyrics[_LyricSubDuet].Visible = isDuet; - - if (isDuet) - { - _Lyrics[_LyricMainTop].Visible = false; - _Lyrics[_LyricSubTop].Visible = false; - _Statics[_StaticLyricsTop].Visible = false; - } - else - { - bool lyricsOnTop = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_TOP - || CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH - || (CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && _DynamicLyricsTop); - _Lyrics[_LyricMainTop].Visible = lyricsOnTop; - _Lyrics[_LyricSubTop].Visible = lyricsOnTop; - _Statics[_StaticLyricsTop].Visible = lyricsOnTop; - } } private void _SetNormalLyricsVisibility() { - bool visible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTTOM + bool bottomLyricsVisible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTTOM || CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH || (CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && _DynamicLyricsBottom); - _Lyrics[_LyricMain].Visible = visible; - _Lyrics[_LyricSub].Visible = visible; - _Statics[_StaticLyrics].Visible = visible; + + bool topLyricsVisible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_TOP + || CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTH + || (CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_DYNAMIC && _DynamicLyricsTop); + + bool duetLyricsVisible = false; + + if (CGame.GetSong() != null && CGame.GetSong().IsDuet) + { + bottomLyricsVisible = true; + topLyricsVisible = false; + duetLyricsVisible = true; + } + + _Lyrics[_LyricMain].Visible = bottomLyricsVisible; + _Lyrics[_LyricSub].Visible = bottomLyricsVisible; + _Statics[_StaticLyrics].Visible = bottomLyricsVisible; + + _Lyrics[_LyricMainTop].Visible = topLyricsVisible; + _Lyrics[_LyricSubTop].Visible = topLyricsVisible; + _Statics[_StaticLyricsTop].Visible = topLyricsVisible; + + _Lyrics[_LyricMainDuet].Visible = duetLyricsVisible; + _Lyrics[_LyricSubDuet].Visible = duetLyricsVisible; + _Statics[_StaticLyricsDuet].Visible = duetLyricsVisible; } private void _StartSong() From 8244fd638b2b049a04729e0f3b44bddc33a6eebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:56:37 +0200 Subject: [PATCH 07/14] Log missing avatar as error instead of throwing exceptions --- VocaluxeLib/Profile/CProfile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VocaluxeLib/Profile/CProfile.cs b/VocaluxeLib/Profile/CProfile.cs index 2e168b97..828c2f1c 100644 --- a/VocaluxeLib/Profile/CProfile.cs +++ b/VocaluxeLib/Profile/CProfile.cs @@ -67,7 +67,7 @@ namespace VocaluxeLib.Profile { Avatar = CBase.Profiles.GetAvatarByFilename(value); if (Avatar == null) - throw new Exception("Avatar '" + value + "' not found"); + CBase.Log.LogError("Avatar '" + value + "' not found"); } } From 4d754c0876ef354b8516e77ccd3776206d2e6bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 8 Oct 2017 12:59:46 +0200 Subject: [PATCH 08/14] Forget to remove a function... --- Vocaluxe/Screens/CScreenSing.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index c082e1bd..2a0fa1b9 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -201,8 +201,6 @@ namespace Vocaluxe.Screens CConfig.Config.Theme.PlayerInfo = (EPlayerInfo)mode; CConfig.SaveConfig(); _SetVisibility(); - if (CGame.GetSong() != null) - _SetDuetLyricsVisibility(CGame.GetSong().IsDuet); //make sure duet lyrics remain visible break; case Keys.S: @@ -596,7 +594,6 @@ namespace Vocaluxe.Screens _DynamicLyricsTop = true; } - _SetDuetLyricsVisibility(song.IsDuet); _SetNormalLyricsVisibility(); _TimerSongText.Reset(); @@ -609,10 +606,6 @@ namespace Vocaluxe.Screens _StartSong(); } - private void _SetDuetLyricsVisibility(bool isDuet) - { - } - private void _SetNormalLyricsVisibility() { bool bottomLyricsVisible = CConfig.Config.Game.LyricsPosition == ELyricsPosition.TR_CONFIG_LYRICSPOSITION_BOTTOM From 3e0eec829422c0f7ff747b00530438e77febc98a Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 14:58:48 +0100 Subject: [PATCH 09/14] Synchronize access to _PreviewStartHelperTask object (may fixes #330) --- Vocaluxe/Base/CBackgroundMusic.cs | 64 ++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 65165cf4..f9146f12 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -51,6 +51,7 @@ namespace Vocaluxe.Base private static Task _PreviewStartHelperTask; private static int _PreviewStartWaitCounter; private const int _PreviewStartWaitMaxTries = 10; + private static readonly object _PreviewStartHelperTaskLock = new Object(); public static bool VideoEnabled { @@ -256,10 +257,17 @@ namespace Vocaluxe.Base { if (_PreviewStartHelperTask != null && ( _PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries)) { - _PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); - _PreviewStartHelperTask.Dispose(); - _PreviewStartHelperTask = null; - _PreviewStartWaitCounter = 0; + lock (_PreviewStartHelperTaskLock) + { + // Recheck the condition as it cloud have change before we got the lock + if (_PreviewStartHelperTask != null && (_PreviewPlayer.Length > 0 || _PreviewStartWaitCounter++ >= _PreviewStartWaitMaxTries)) + { + _PreviewStartHelperTask.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext()); + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; + _PreviewStartWaitCounter = 0; + } + } } if (!IsPlaying) @@ -317,28 +325,46 @@ namespace Vocaluxe.Base //Change song position only if song is changed or near to end if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length) { - _PreviewStartHelperTask = new Task(() => + lock (_PreviewStartHelperTaskLock) { - float length = _PreviewPlayer.Length; - if (length < 1) - length = 30; // If length is unknow or invalid assume a length of 30s + // Check if the old _PreviewStartHelperTask needs to disposed + if (_PreviewStartHelperTask != null) + { + _PreviewStartHelperTask.Dispose(); + } + _PreviewStartHelperTask = new Task(() => + { + float length = _PreviewPlayer.Length; + if (length < 1) + length = 30; // If length is unknow or invalid assume a length of 30s - if (start < 0) - start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; - if (start > length - 5f) - start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); - if (start >= 0.5f) - start -= 0.5f; + if (start < 0) + start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime; + if (start > length - 5f) + start = Math.Max(0f, Math.Min(length / 4f, length - 5f)); + if (start >= 0.5f) + start -= 0.5f; - _PreviewPlayer.Position = start; - Play(); - }); + _PreviewPlayer.Position = start; + Play(); + }); + } _CurPlayer = _PreviewPlayer; } else { - _PreviewStartHelperTask.Dispose(); - _PreviewStartHelperTask = null; + if (_PreviewStartHelperTask != null) + { + lock (_PreviewStartHelperTaskLock) + { + // Recheck the condition as it cloud have change before we got the lock + if (_PreviewStartHelperTask != null) + { + _PreviewStartHelperTask.Dispose(); + _PreviewStartHelperTask = null; + } + } + } _PreviewPlayer.Position = _CurPlayer.Position; _CurPlayer = _PreviewPlayer; Play(); From a92353c9a2dab0cce7d97cb62be6dc05d937905f Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 19:34:55 +0100 Subject: [PATCH 10/14] Try to fix exceptions while closing Vocaluxe (during closing bg video) (may fixes #320) --- Vocaluxe/Base/CMain.cs | 27 ++++++- Vocaluxe/Base/CVideo.cs | 73 +++++++++++++++++++ .../Record/PortAudio/CPortAudioRecord.cs | 16 +++- 3 files changed, 110 insertions(+), 6 deletions(-) diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 3a131649..b8ec6bfe 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -822,7 +822,14 @@ namespace Vocaluxe.Base public void Close(ref CVideoStream stream) { - CVideo.Close(ref stream); + try + { + CVideo.Close(ref stream); + } + catch (NotSupportedException e) + { + CLog.LogError($"Clould not close the background video: {e.Message}"); + } } public void SetLoop(CVideoStream stream, bool loop = true) @@ -832,12 +839,26 @@ namespace Vocaluxe.Base public void Pause(CVideoStream stream) { - CVideo.Pause(stream); + try + { + CVideo.Pause(stream); + } + catch (NotSupportedException e) + { + CLog.LogError($"Clould not pause the background video: {e.Message}"); + } } public void Resume(CVideoStream stream) { - CVideo.Resume(stream); + try + { + CVideo.Resume(stream); + } + catch (NotSupportedException e) + { + CLog.LogError($"Clould not resume the background video: {e.Message}"); + } } } diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index d9400cc8..d9af124b 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -15,6 +15,7 @@ // along with Vocaluxe. If not, see . #endregion +using System; using Vocaluxe.Lib.Video; using VocaluxeLib; @@ -61,6 +62,10 @@ namespace Vocaluxe.Base public static CVideoStream Load(string videoFileName) { + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } return _VideoDecoder.Load(videoFileName); } @@ -73,41 +78,109 @@ namespace Vocaluxe.Base public static float GetLength(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.GetLength(stream); } public static bool GetFrame(CVideoStream stream, float time) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.GetFrame(stream, time); } public static bool Skip(CVideoStream stream, float start, float gap) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.Skip(stream, start, gap); } public static void SetLoop(CVideoStream stream, bool loop) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.SetLoop(stream, loop); } public static void Pause(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.Pause(stream); } public static void Resume(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.Resume(stream); } public static bool Finished(CVideoStream stream) { + if (stream == null) + { + throw new ArgumentException("stream is null"); + } + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + return _VideoDecoder.Finished(stream); } public static void Update() { + if (_VideoDecoder == null) + { + throw new NotSupportedException("_VideoDecoder is null (already closed?)"); + } + _VideoDecoder.Update(); } #endregion Interface diff --git a/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs b/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs index 4702e400..cfc8818c 100644 --- a/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs +++ b/Vocaluxe/Lib/Sound/Record/PortAudio/CPortAudioRecord.cs @@ -16,6 +16,8 @@ #endregion using System; +using System.Collections.Generic; +using System.Linq; using System.Runtime.InteropServices; using System.Threading; using Vocaluxe.Base; @@ -142,9 +144,13 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio foreach (IntPtr handle in _RecHandle) { - PortAudioSharp.PortAudio.Pa_StopStream(handle); - PortAudioSharp.PortAudio.Pa_CloseStream(handle); + if (handle != IntPtr.Zero) + { + PortAudioSharp.PortAudio.Pa_StopStream(handle); + PortAudioSharp.PortAudio.Pa_CloseStream(handle); + } } + _RecHandle = new IntPtr[_Devices.Count]; return true; } @@ -153,13 +159,17 @@ namespace Vocaluxe.Lib.Sound.Record.PortAudio /// public override void Close() { - if (_RecHandle != null) + if (_RecHandle != null && _RecHandle.Length > 0) { foreach (IntPtr handle in _RecHandle) { if (handle != IntPtr.Zero) + { _PaHandle.CloseStream(handle); + } } + + _RecHandle = new IntPtr[_Devices.Count]; } if (_PaHandle != null) { From 79bbcbdccb0eb54f2b8e1e6f0090ffd6a404c48d Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 19:47:47 +0100 Subject: [PATCH 11/14] Try to close the other modules correctly if a single one fails to close ( on program shutdown) --- Vocaluxe/Program.cs | 99 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index d18660db..136508fd 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -285,23 +285,120 @@ namespace Vocaluxe try { CController.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CController)", false, false, e); + } + + try + { CVocaluxeServer.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CVocaluxeServer)", false, false, e); + } + + try + { CGraphics.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CGraphics)", false, false, e); + } + + try + { CThemes.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CThemes)", false, false, e); + } + + try + { CCover.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CCover)", false, false, e); + } + + try + { CFonts.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CFonts)", false, false, e); + } + + try + { CBackgroundMusic.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CBackgroundMusic)", false, false, e); + } + + try + { CWebcam.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CWebcam)", false, false, e); + } + + try + { CDataBase.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CDataBase)", false, false, e); + } + + try + { CVideo.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CVideo)", false, false, e); + } + + try + { CRecord.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CRecord)", false, false, e); + } + + try + { CSound.Close(); + } + catch (Exception e) + { + CLog.LogError("Error during shutdown! (CSound)", false, false, e); + } + + try + { CDraw.Close(); } catch (Exception e) { - CLog.LogError("Error during shutdown!", false, false, e); + CLog.LogError("Error during shutdown! (CDraw)", false, false, e); } + GC.Collect(); // Do a GC run here before we close logs to have finalizers run try { From 52f1b8f5463fb45bceb70b31e76a5f047288d362 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Sat, 4 Nov 2017 20:13:19 +0100 Subject: [PATCH 12/14] Fix: Vocaluxe crashes when _CopyDecodedFrameToBuffer() fails --- Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs b/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs index 38275210..3d7229d0 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CDecoderThread.cs @@ -429,7 +429,18 @@ namespace Vocaluxe.Lib.Video.Acinerella private bool _CopyDecodedFrameToBuffer() { bool result; - var decoder = (SACDecoder)Marshal.PtrToStructure(_Videodecoder, typeof(SACDecoder)); + SACDecoder decoder; + + try + { + decoder = (SACDecoder)Marshal.PtrToStructure(_Videodecoder, typeof(SACDecoder)); + } + catch (Exception e) + { + CLog.LogError("Couldn't copy the frame to the managed environment.", false, false, e); + return false; + } + if (decoder.Buffer != IntPtr.Zero) { _LastDecodedTime = (float)decoder.Timecode; From ce4529325bc1e8eec642a2c0ebbf1f40770c105e Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Mon, 6 Nov 2017 10:08:06 +0100 Subject: [PATCH 13/14] Fix: exception when intro video is missing --- Vocaluxe/Base/CVideoPlayer.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Base/CVideoPlayer.cs b/Vocaluxe/Base/CVideoPlayer.cs index 3e0762f6..1f451396 100644 --- a/Vocaluxe/Base/CVideoPlayer.cs +++ b/Vocaluxe/Base/CVideoPlayer.cs @@ -53,6 +53,10 @@ namespace Vocaluxe.Base { _VideoTimer.Reset(); _Finished = false; + if (_VideoStream == null) + { + return; + } //CVideo.VdSkip(_VideoStream, 0f, 0f); _VideoTimer.Start(); CVideo.Resume(_VideoStream); @@ -60,12 +64,19 @@ namespace Vocaluxe.Base public void Pause() { - CVideo.Pause(_VideoStream); + if (_VideoStream != null) + { + CVideo.Pause(_VideoStream); + } _VideoTimer.Stop(); } public void Resume() { + if (_VideoStream == null) + { + return; + } CVideo.Resume(_VideoStream); _VideoTimer.Start(); } @@ -92,7 +103,7 @@ namespace Vocaluxe.Base public void PreLoad() { - if (!_Loaded) + if (!_Loaded || _VideoStream == null) { return; } @@ -111,7 +122,10 @@ namespace Vocaluxe.Base public void Close() { - CVideo.Close(ref _VideoStream); + if (_VideoStream != null) + { + CVideo.Close(ref _VideoStream); + } _Loaded = false; _Finished = false; _VideoTimer.Reset(); From 06d6be528a0c35181edf41b130000bcd0b7e4519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Thu, 16 Nov 2017 12:26:38 +0100 Subject: [PATCH 14/14] Fixed wrong song folder path that leads to not working folder-sorting --- Vocaluxe/Base/CConfig.cs | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 7db2f250..1b7fde8e 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -191,13 +191,14 @@ namespace Vocaluxe.Base public static event OnSongMenuChanged SongMenuChanged; //Folders + //We need full path for folders for matching folder path with textfile path when loading public static readonly List SongFolders = new List { #if INSTALLER Path.Combine(CSettings.DataFolder, CSettings.FolderNameSongs), - CSettings.FolderNameSongs + Path.Combine(CSettings.ProgramFolder, FolderNameSongs) #elif WIN - CSettings.FolderNameSongs + Path.Combine(CSettings.ProgramFolder, CSettings.FolderNameSongs) #elif LINUX Path.Combine(CSettings.DataFolder, CSettings.FolderNameSongs) #endif @@ -335,15 +336,8 @@ namespace Vocaluxe.Base else Config = xml.DeserializeString(""); - if (Config.Game.SongFolder.Length > 0 && Config.Game.SongFolder[0] != "") - { - SongFolders.Clear(); - SongFolders.AddRange(Config.Game.SongFolder); - } - else - { - Config.Game.SongFolder = SongFolders.ToArray(); - } + NormalizeSongPaths(); + if ((Config.Game.ScoreAnimationTime > 0 && Config.Game.ScoreAnimationTime < 1) || Config.Game.ScoreAnimationTime < 0) Config.Game.ScoreAnimationTime = 1; @@ -625,6 +619,29 @@ namespace Vocaluxe.Base return false; } + /// + /// Set song path if none is find in config and check if every path exists + /// + public static void NormalizeSongPaths() + { + //Check if there are configured songfolders + if (Config.Game.SongFolder.Length > 0 && Config.Game.SongFolder[0] != "") + { + SongFolders.Clear(); + + foreach (string folder in Config.Game.SongFolder) + { + //Check if folder exists + if (Directory.Exists(folder)) + SongFolders.Add(folder); + } + } + + //Test if songfolders are still empty or now empty + if(Config.Game.SongFolder.Length == 0) + Config.Game.SongFolder = SongFolders.ToArray(); + } + /// /// Load command-line-parameters and their values to lists. ///