From d1bce790dfe3e9817273cef21a427868805c4568 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 27 Jan 2016 07:19:43 +0100 Subject: [PATCH] stop works properly now, was causing memory leaks --- NadekoBot/Classes/Music/MusicControls.cs | 10 ++++++++++ NadekoBot/Classes/Music/StreamRequest.cs | 4 ++-- NadekoBot/Modules/Music.cs | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/NadekoBot/Classes/Music/MusicControls.cs b/NadekoBot/Classes/Music/MusicControls.cs index f57a4880..03e18e86 100644 --- a/NadekoBot/Classes/Music/MusicControls.cs +++ b/NadekoBot/Classes/Music/MusicControls.cs @@ -42,5 +42,15 @@ namespace NadekoBot.Classes.Music { CurrentSong.Start(); Console.WriteLine("starting"); } + + internal void RemoveAllSongs() { + lock (SongQueue) { + foreach (var kvp in SongQueue) { + if(kvp != null) + kvp.Cancel(); + } + SongQueue.Clear(); + } + } } } diff --git a/NadekoBot/Classes/Music/StreamRequest.cs b/NadekoBot/Classes/Music/StreamRequest.cs index a9099696..cca03e1c 100644 --- a/NadekoBot/Classes/Music/StreamRequest.cs +++ b/NadekoBot/Classes/Music/StreamRequest.cs @@ -168,10 +168,10 @@ namespace NadekoBot.Classes.Music { return; } - if (buffer.Length > 5.MB()) { // if buffer is over 10 MB, create new one + if (buffer.readPos > 10.MiB()) { // if buffer is over 10 MiB, create new one Console.WriteLine("Buffer over 10 megs, clearing."); - var skip = 2.MB(); + var skip = 10.MB(); //remove only 10 MB, just in case byte[] data = buffer.ToArray().Skip(skip).ToArray(); lock (_bufferLock) { diff --git a/NadekoBot/Modules/Music.cs b/NadekoBot/Modules/Music.cs index 897cdbd5..1f71ed41 100644 --- a/NadekoBot/Modules/Music.cs +++ b/NadekoBot/Modules/Music.cs @@ -71,7 +71,7 @@ namespace NadekoBot.Modules { .Do(e => { if (musicPlayers.ContainsKey(e.Server) == false) return; var player = musicPlayers[e.Server]; - player.SongQueue.Clear(); + player.RemoveAllSongs(); if (player.CurrentSong != null) { player.CurrentSong.Cancel(); player.CurrentSong = null;