Comments (12)
Using the _disposed
syntax is considered best practice. It might be better to add the null
-check right before the expression that causes this crash. Feels better, imho, and should cause less sideeffects we can't even think of at the moment.
from cscore.
Ok, then the fix requires a tiny bit more code, but doable.
Personally I do not agree with many best practices; after 25 years of fulltime software development, I see many "best practices" swing like a pendulum ;-)
from cscore.
So do I ;) But I was wondering why your pull request is in the queue for like two months now, and that was my guess. I encountered the same exception today, and came looking if some else already encountered this issue.
Looking at Dispose
, I wonder if it would need more hardening. Alas, as far as I can see, there is no IsDisposing
or IsDisposed
in the WaveWriter. So when calling Dispose()
, the caller needs to ensure that no thread calls Writer
from the WaveWriter. And two threads should never access Dispose()
at the same time, so the caller needs some more synching here.
But that are only whishes and just my two cents. All in all, it's an awesome library.
from cscore.
Oh, I even did not know that your classes were thread safe.
from cscore.
My classes? I'm not the author, just a random stranger. :)
from cscore.
Lol, sorry, I guess I was a bit too impulsive here ;-)
from cscore.
If the constructor crashes, there won't be any instance to dispose. Am I wrong?
from cscore.
Thanks for jumping in filoe.
Unfortunately you are - the finalizer will be called when you've got an exception in the constructor. Because there is no distinction between managed and unmanaged resources in Dispose()
(that's the idea of the disposing
var, as the comment says ;) ), an exception will be thrown.
As a bonus: For the user, it would be good to know if the object is in an "disposing" state, because then the user can block concurrent access to the write method - and it might take a while to write the header to the wav file on large files.* So a simple IsDisposing
property would be awesome. And, for the sake of completeness, what will happen if I access the object after it being disposed? An IsDisposed
would make sense, at least from my point of view.
* Edit: Just realized you are already reserving the space for the header. Shouldn't depend on the filesize, just on plain i/o speed.
from cscore.
True, but the finalizer is called, so Dispose is called indirectly. I made a small test program to confirm this.
.NET always allocates the object (zeroed) before calling the constructor... So it will be finalized, since memory was allocated for it.
If you want to avoid these problems, then make a static method WaveWriter.FromFilePath instead. And just keep dummy constructors that cannot fail, or wrap the constructor bodies in try/catch, calling Dispose in the catch and rethrowing. Ugly, and could be avoided if the CLR would evaluate all arguments passed to a constructor before allocating an object, but helas...
from cscore.
Sometimes I even ended up with an enumeration and property LifeCycle { Allocated, Constructing, Constructed, Disposing, Disposed } ;-)
from cscore.
FYI, I've made a suggestion for a change to this class. Let me know your constructive feedback. 😃
from cscore.
Thanks for your contribution. Got merged :).
from cscore.
Related Issues (20)
- 'System.InvalidCastException' occurred in CSCore. Unable to cast object of type 'NAudio.CoreAudioApi.Interfaces.MMDeviceEnumeratorComObject' to type 'MMDeviceEnumeratorObject'. HOT 4
- Is it possible to process audio based on LUFS scale? HOT 1
- In SpectrumBase.cs ,why " _maxFftIndex = _fftSize / 2 - 1 " ? HOT 4
- Convert a MemoryStream to IAudioSource? HOT 5
- microphone audio as input to another microphone? HOT 1
- Recording on WasapiCapture,a lot of noise. HOT 4
- Duplicate values in AudioSubTypes
- CSCORE AudioClient initializing problem or problem elsewhere? HOT 2
- Which license is intended?
- [Question] peak sound HOT 3
- [Question] Any plans to update it to .NET core/5-6 versions?
- [Question] Getting playback position with WriteableBufferingSource ? HOT 1
- PropertyStore constains not all keys
- Clear WriteableBufferingSource?
- How to prevent WasapiOut to change Device when soundouput changes
- Doesn't build HOT 2
- Is it possible to play audio using RTP Payload?
- Real-time processing left and right channel
- Supported Still? HOT 1
- [QUESTION] Is it possible to run on a Linux server with .Net 8?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cscore.