# AudioSampleBuffer operator=

**URL:** <https://forum.juce.com/t/audiosamplebuffer-operator/2158>\
**Category:** General JUCE discussion\
**Created:** [October 10, 2007, 10:14am UTC](https://forum.juce.com/t/audiosamplebuffer-operator/2158 "2007-10-10T10:14:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cialz](https://avatars.discourse-cdn.com/v4/letter/c/8c91f0/32.png) [@cialz](https://forum.juce.com/u/cialz)\
**Post date:** [October 10, 2007, 10:14am UTC](https://forum.juce.com/t/audiosamplebuffer-operator/2158/1 "2007-10-10T10:14:39Z")

</div>

Hi to all,  
I need to keep a copy of the input AudioSampleBuffer of the VST plugin, so the editor can draw a waveform preview.

So I instanciate an AudioSampleBuffer in the prepareToPlay method:

```auto
void MyFilter::prepareToPlay (double sampleRate, int samplesPerBlock)
{
  ...
  deleteAndZero(m_pLastInputBuffer);
  m_pLastInputBuffer = new AudioSampleBuffer(m_nInputs, samplesPerBlock);
  ...
}
```

In the proceccBlock callback I do as follows:

```auto
void MyFilter::processBlock (const AudioSampleBuffer& input, 
                              AudioSampleBuffer& output,
                              const bool accumulateOutput,
                              MidiBuffer& /*midiMessages*/)
{
  m_pLastInputBuffer->clear();
  *m_pLastInputBuffer = input;
  ...
}
```

The plugin crashes in the memcpy call inside the copy constructor code.  
I’ve notified that input.allocatedData is NULL.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 10, 2007, 10:36am UTC](https://forum.juce.com/t/audiosamplebuffer-operator/2158/2 "2007-10-10T10:36:09Z")

</div>

ooh - yes, there seems to be a bug in operator=

Sorry about that, I’ve checked in a fixed version now. Thanks for spotting it!

---

<div class="post-metadata">

**Author:** ![cialz](https://avatars.discourse-cdn.com/v4/letter/c/8c91f0/32.png) [@cialz](https://forum.juce.com/u/cialz)\
**Post date:** [October 12, 2007, 10:10am UTC](https://forum.juce.com/t/audiosamplebuffer-operator/2158/3 "2007-10-12T10:10:04Z")

</div>

Thanx Jules for the fix

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 10:06am UTC](https://forum.juce.com/t/audiosamplebuffer-operator/2158/4 "2017-05-12T10:06:48Z")

</div>


