# Read access violation using AudioSampleBuffer::getWritePointer()

**URL:** <https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686>\
**Category:** Audio Plugins\
**Created:** [December 21, 2017, 1:26pm UTC](https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686 "2017-12-21T13:26:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![toxictomdude](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toxictomdude/32/3497_2.png) [@toxictomdude](https://forum.juce.com/u/toxictomdude)\
**Post date:** [December 21, 2017, 1:26pm UTC](https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686/1 "2017-12-21T13:26:18Z")

</div>

Not sure what this error really means or how memory management works at all, I’ve just been playing with some DSP algorithms and ran into this problem. The issue is in the process() function of a delay class I wrote, which works fine when used normally but when trying to use it inside a chorus class (to make the chorus effect) it throws this exception. Anyway if you have any advice that would be much appreciated.

```
    //get a pointer to the circular buffer
	float* buff = m_buffer.getWritePointer(0);

	//read the input, xn, from the incoming sample
	float xn = in;

	//read the output, yn, from the circular buffer at the read position
	float yn1 = buff[m_indexRead1];
	float yn2 = buff[m_indexRead2];

```

The exception happens at the float yn1 = buff[m\_indexRead1]; line.

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [December 21, 2017, 1:36pm UTC](https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686/2 "2017-12-21T13:36:33Z")

</div>

obviously m\_indexRead1is out of the index range, use a debugger and look which value it has

---

<div class="post-metadata">

**Author:** ![toxictomdude](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/toxictomdude/32/3497_2.png) [@toxictomdude](https://forum.juce.com/u/toxictomdude)\
**Post date:** [December 21, 2017, 7:42pm UTC](https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686/3 "2017-12-21T19:42:21Z")

</div>

Ok I guess that’s the problem, think I was feeding some negative numbers in there 🤦‍♂️

Secondary question:  
How do you use the Visual Studio debugger when debugging a VST inside a host?

Thanks!

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [December 21, 2017, 7:45pm UTC](https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686/4 "2017-12-21T19:45:25Z")

</div>

In the plugin project properties set the executable (command) to use when debugging :

 ![](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/2/24902494a20f15a8b5b3ae1861fd6057b7802251.png)

F5 will then launch the debugger and the host.

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [December 21, 2017, 8:36pm UTC](https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686/5 "2017-12-21T20:36:27Z")

</div>

I suggest using the JUCE Plugin Host for initial development.

Rail

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 21, 2017, 11:28pm UTC](https://forum.juce.com/t/read-access-violation-using-audiosamplebuffer-getwritepointer/25686/6 "2017-12-21T23:28:39Z")

</div>

> [@toxictomdude](#):
>
> Ok I guess that’s the problem, think I was feeding some negative numbers in there 🤦‍♂️

Pro tip: if it happened once, it will happen again. Add this line before:

```
jassert (m_indexRead1 >= 0);

```

That way it will stop in debug mode exactly at the right point, not just crashing eventually…
