Skip to content

Commit

Permalink
Should fix filoe#138.
Browse files Browse the repository at this point in the history
  • Loading branch information
filoe committed Aug 28, 2016
1 parent e9120ab commit af0477c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions CSCore/Codecs/WAV/WaveWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class WaveWriter : IDisposable, IWriteable
private BinaryWriter _writer;
private bool _isDisposing;

private readonly bool _disposeStream;

/// <summary>
/// Signals if the object has already been disposed
/// </summary>
Expand Down Expand Up @@ -52,6 +54,7 @@ public bool IsDisposing
public WaveWriter(string fileName, WaveFormat waveFormat)
: this(File.OpenWrite(fileName), waveFormat)
{
_disposeStream = false;
}

/// <summary>
Expand Down Expand Up @@ -83,6 +86,8 @@ public WaveWriter(Stream stream, WaveFormat waveFormat)
_waveFormat = waveFormat;

WriteHeader();

_disposeStream = true;
}

/// <summary>
Expand Down Expand Up @@ -324,16 +329,19 @@ protected virtual void Dispose(bool disposing)
}
finally
{
if (_writer != null)
{
_writer.Close();
_writer = null;
}

if (_stream != null)
if (_disposeStream)
{
_stream.Close();
_stream = null;
if (_writer != null)
{
_writer.Close();
_writer = null;
}

if (_stream != null)
{
_stream.Close();
_stream = null;
}
}

_isDisposing = false;
Expand Down

0 comments on commit af0477c

Please sign in to comment.