title: Exception thrown: write access violation. this was nullptr
body: <p>So I am trying to make a buffer class. This buffer class contains a huge buffer of size 384*4. The plan was for every UDP datagram received, size(384), the buffer class is called and return a pointer to where the datagram should be written.</p>
  
  <p>And there will be another listener pointer to which RtAudio playback will memcpy from. <strong>[The listening part is not entirely relevant yet as I still have a problem writing into the buffer]</strong></p>
  
  <p>When I try to call server_->getPointer() <strong>(shown below)</strong>, the "<code>Exception thrown: write access violation. this was nullptr.</code>" is thrown. Please help me!! and tell me if there is anything else that I should provide.</p>
  
  <p>Buffer.h  </p>
  
  <pre><code>#pragma once
  
  #ifndef BUFFER_H
  #define BUFFER_H
  
  
  
  class Buffer {
  private:
      int bufferSize = 192 * 2; // one frame takes 2 Byte [int16]
      int nBuffers = 4;
  
      int *buffer_ = nullptr;
  
      int* writerPointer = nullptr;
      int* listenerPointer = nullptr;
  
      int writerCounter = 0;
      int listenerCounter = 0;
  
      int* tempW = nullptr;
      int* tempL = nullptr;
  
  public:
      Buffer();
      ~Buffer();
      int* getWriterPointer();
      int* getlistenerPointer();
      int * getPointer();
  };
  
  #endif // !BUFFER_H
  </code></pre>
  
  <p>Buffer.cpp</p>
  
  <pre><code>#include"Buffer.h"
  #include &lt;iostream&gt;
  
  
  Buffer::Buffer() {
      buffer_ = reinterpret_cast&lt;int*&gt;(malloc(bufferSize*nBuffers));
      memset(buffer_, (int)5, bufferSize*nBuffers);
  
      std::cout &lt;&lt; "new Buffer" &lt;&lt; bufferSize * nBuffers &lt;&lt; std::endl;
      listenerPointer = buffer_;
      writerPointer = buffer_;
      std::cout &lt;&lt; "HERE " &lt;&lt; *buffer_ &lt;&lt; std::endl;
      std::cout &lt;&lt; "new Buffer" &lt;&lt; bufferSize * nBuffers &lt;&lt; " pointer a " &lt;&lt; listenerPointer &lt;&lt; " pointer b " &lt;&lt; writerPointer &lt;&lt; std::endl;
  }
  
  Buffer::~Buffer() {
      delete buffer_;
  }
  
  ...
  
  //For teting purposes
  int* Buffer::getPointer(){
      bufferSize = 192 * 2;
      std::cout &lt;&lt; "get pointer asdfasdf::" &lt;&lt; writerCounter &lt;&lt; std::endl;
      std::cout &lt;&lt; "pointer's position offset: " &lt;&lt; writerCounter - 1 &lt;&lt; std::endl;
  
      if (writerCounter == nBuffers - 1) {
          writerCounter = 0;
          return writerPointer + (bufferSize*(nBuffers - 1));
      }
      else {
          writerCounter += 1;
          return writerPointer + (bufferSize*(writerCounter - 1));
      }
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Buffer.h"
  
  
  int main()
  {
      std::cout &lt;&lt; "Hello World!\n"; 
      Buffer *buffer_ = new Buffer();
  
      buffer_-&gt;getPointer();
  
  
  }
  </code></pre>