# \[Bug report\] AudioBuffer makeCopyOf

**URL:** <https://forum.juce.com/t/bug-report-audiobuffer-makecopyof/21856>\
**Category:** General JUCE discussion\
**Created:** [April 17, 2017, 8:34am UTC](https://forum.juce.com/t/bug-report-audiobuffer-makecopyof/21856 "2017-04-17T08:34:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zonrobin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/zonrobin/32/1961_2.png) [@zonrobin](https://forum.juce.com/u/zonrobin)\
**Post date:** [April 17, 2017, 8:34am UTC](https://forum.juce.com/t/bug-report-audiobuffer-makecopyof/21856/1 "2017-04-17T08:34:30Z")

</div>

Hi,

I’d like to report a bug concerning AudioBuffer’s makeCopyOf method.  
When you copy a non-clear buffer (secondBuff) to a cleared buffer (firstBuff), the “isClear” flag of first buffer is still true even though it contains new samples from the secondBuffer. Because of this, you can’t call clear() on the first buffer aferwards.

Test case:

```
AudioBuffer<float> firstBuff(1, 1);
AudioBuffer<float> secondBuff(1, 1);

firstBuff.clear();

float* secondBuffSamples = secondBuff.getWritePointer(0);
secondBuffSamples[0] = 42;

firstBuff.makeCopyOf(secondBuff);	

```

Actual result:

```
firstBuff.hasBeenCleared(); returns true
firstBuff.getSample(0,0); returns 42
firstBuff.clear();
firstBuff.getSample(0,0); returns 42

```

Expected result:

```
firstBuff.hasBeenCleared(); returns false
firstBuff.getSample(0,0); returns 42
firstBuff.clear();
firstBuff.getSample(0,0); returns 0

```

Solution:

[modules/juce\_audio\_basics/buffers/juce\_AudioSampleBuffer.h#L451](https://github.com/julianstorer/JUCE/blob/master/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h#L451) could be changed from

```
Type* const dest = channels[chan];

```

to

```
Type* const dest = getWritePointer(chan);

```

which sets the isClear to false.

I’m using JUCE version 4.3.1.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [April 18, 2017, 8:43am UTC](https://forum.juce.com/t/bug-report-audiobuffer-makecopyof/21856/2 "2017-04-18T08:43:44Z")

</div>

Thanks for the bug report. A fix for this is on the develop branch of JUCE.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [April 18, 2017, 2:41pm UTC](https://forum.juce.com/t/bug-report-audiobuffer-makecopyof/21856/3 "2017-04-18T14:41:09Z")

</div>

Seems like something unit-testable…
