FINALLY FIXED THAT BUG.

It turns out that you must call setBuffer again when you are done capturing a waveform.

Or else, on the next call, it will still try to write to that location.