Help writing buffer to Wav file

Thank you so much!

As almost always, it is something so simple.

making the file and stream member variables of the AudioProcessor alone did not work, returning the exception at memory:

Exception thrown at 0x00007FFA432A19F8 (NewProject.vst3) in AudioPluginHost.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

but from this post (latter saw it is also writen in the documentation) i figured i had to release the stream pointer after creating the writer, and it worked!

so the code ended like this:

// @PluginProcessor.h
class AudioProcessor
{ // ... existing code...
private:
    juce::File file;
    std::unique_ptr<juce::FileOutputStream> stream;
    std::unique_ptr<juce::AudioFormatWriter> writer;
// @PluginProcessor.cpp
perpareToPlay()
{
file.operator=("path/output.wav");

stream = std::make_unique<juce::FileOutputStream>(file);
// safety checks

juce::WavAudioFormat wavFormat;
writer.reset(wavFormat.createWriterFor(
    stream.get(),
    44100,
    2,
    16,
    {},
    0));

stream.release();
}

processBlock()
{
if (writer != nullptr)
   writer->writeFromAudioSampleBuffer(buffer, 0, buffer.getNumSamples());
}

Should i also handle the memory release with something like this?

// @PluginProcessor.cpp
releaseResources()
{ 
   if (writer != nullptr)
    {
        writer.reset();
    }

    if (stream != nullptr)
    {
        stream->flush();
        stream.reset();
    }
}