stop works properly now, was causing memory leaks

This commit is contained in:
Master Kwoth 2016-01-27 07:19:43 +01:00
parent a3d9914d36
commit d1bce790df
3 changed files with 13 additions and 3 deletions

View File

@ -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();
}
}
}
}

View File

@ -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) {

View File

@ -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;