This bug might be interesting for other people as well:
Now the question is, does it make sense to implement Vector in a way that it is not initialized to zero when created? I agree with Andrew from a logical point of view, if you want the exact same behavior as with other simple types like float. But maybe it would be better to initialize it all the time with 0, at the cost that Rack is 2 nanoseconds slower at startup when all variables are allocated, but for the benefit of less bugs in 3rd party plugins, or in VCV plugins like ADSR.
Yes, of course.
I also think initialization should be done by me when declaring a variable, just like float.
But people forget it, and even experienced developers like Andrew don’t initialize all variables all the time, as the ADSR.cpp bug itself demonstrates. How can we automatically detect such bugs? I’m not sure, if e.g. Valgrind would detect it, because it only detects it, if the uninitialized value is used in functions like printf:
http://valgrind.org/docs/manual/mc-manual.html#mc-manual.uninitvals
The drawback would be minimal. As Andrew noted earlier in the issue with his first fix, which initializes it to zero, big arrays are allocated outside of process, and for variables on the stack it doesn’t matter much.
To my knowledge initialization of primitive types is not done because of the overhead involved when passing “by value”.
I didn’t forget to initialize VCV ADSR member variables. The mistake was that I assumed Vector
was a POD type, which is wasn’t. A recent change to Vector
fixes this.
I’ll tell you what, if it is poly initialize that array!