I have a reasonably complex application where an NAudio WaveIn stream is started and seems to run correctly. The input has two 44,100 channels. But if additional windows in the application are opened the application
falls over with an "Access violation on location 0x00000000". These additional windows have nothing to do with NAudio code. The OS is Windows 7.
On investigation it appears that the problem only occurs if the waveIn BufferMilliseconds value has been increased to 482 milliseconds or greater, giving a buffer over 85,000 bytes. It is possible the crash may be connected
to the garbage collector coming in soon after the additional, and memory hungry, application windows open.
Suspecting a memory issue I changed the following code in the NAudio file WaveInBuffer.cs so the 'header' value is now 'pinned'. This seems to fix the problem.
//hHeader = GCHandler.Alloc(header);
hHeader = GCHandler.Alloc(header, GCHandlerType.Pinned);
I am not certain of the exact difference between the GCHandlerTypes 'Normal' and 'Pinned' but it may be worthwhile making this change to NAudio.