JUCE::develop Compile Errors

LAMEEncoderAudioFormat::Writer on develop won’t compile because the return type of createOutputStream has changed.

I think the code should be something like:

        if (auto out = tempWav.getFile().createOutputStream())
        {
            writer.reset (wavFormat.createWriterFor (out.get(), sampleRate, numChannels,
                                                     bitsPerSample, metadata, 0));
            
            if (writer)
                out.release();

This outputStream, get(), release() paradigm is a bit confusing when using AudioFormatWriters. It would be very easy to just release the stream and then leak it if a writer can’t be created. I wonder if there’s a better way to enforce that?


Similarly, line 205 of juce_mac_AudioCDReader.mm fails.
I think that should be:

            if (auto in = tracks[track].createInputStream())
            {
                BufferedInputStream* const bin = new BufferedInputStream (in.release(), 65536, true);

I agree.

As long as overloads of createWriterFor immediately capture the raw ptr in a unique_ptr, there shouldn’t be any danger of leakage (although I guess there are edge cases where one of the other arguments to createWriteFor might be an expression that throws an exception…). Ideally we’d pass a unique_ptr in the interface instead, but that would force changes in an awful lot of code (both subclasses and clients of AudioFormat). Does the cost of leaving it the way it is outweigh the cost of fixing it? I’m not sure.

Should be fixed on develop:

https://github.com/WeAreROLI/JUCE-dev/commit/0c9067c9a46edac5334a56c7f9c44642eba3fd30

1 Like

I think the problem is when you try and create a writer for a stream that it doesn’t support.
Tbh, this is unlikely to happen in practice but could happen if you pass some other incorrect options to the createWriterFor such as bit depths or sample rates.

I’m struggling to think of cases where you’d need to then keep the stream and try and open a writer again though so passing a std::unique_ptr<OutputStream> is probably safest and makes the most sense.

However, as you say, this will break a lot of code and subclasses.
I’m not sure if that’s a price worth paying. I would say that when changes like these are made they’re a pain (I typically lose a few hours updating and rebuilding all our projects and modules etc.) but the code is much easier to reason about afterwards.

One final warning (error with -Werror) is an unused member in VSTPluginWindow on macOS:
float nativeScaleFactor = 1.0f;

I think this should be in the #if ! JUCE_MAC section above.

1 Like