naudiodon: Segfault Issues

Hi, similar to a few other users on here I am getting repeated Segfault errors causing node js to crash. I am playing a short audio clip on loop (2s long). The error occurs after ~5-20seconds, but always occurs pretty early on. It only occurs when outputting audio through naudiodon (I have tested piping to a file and error does not occur).

Unlike a most others I do not use electron, It is a custom audio application, with other dependencies, but this error only occurs when the pipe to naudiodon. I recieve a slightly different (and often earlier) segfault error when piping to an audio device which exists, but is not connected to any speakers, which directly references naudiodon, but get a very similar error even if I avoid this use case.

Error when sending to audio device not attached to speakers:

PID 1420 received SIGSEGV for address: 0x9b95a799
SymInit: Symbol-SearchPath: '.;C:\Users\emina\OneDrive\Room\Subsystems\Host\node_server;C:\Program Files\nodejs;C:\WINDOWS;C:\WINDOWS\system32;SRV*C:\websymbols*http://msdl.microsoft.com/download/symbols;', symOptions: 530, UserName: 'emina'
OS-Version: 10.0.18363 () 0x100-0x1
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\segfault-handler\src\stackwalker.cpp (924): StackWalker::ShowCallstack
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\segfault-handler\src\segfault-handler.cpp (242): segfault_handler
00007FFF9E1785B6 (ntdll): (filename not available): RtlIsGenericTableEmpty
00007FFF9E16A056 (ntdll): (filename not available): RtlRaiseException
00007FFF9E169FC3 (ntdll): (filename not available): RtlRaiseException
00007FFF9B95A799 (KERNELBASE): (filename not available): RaiseException
d:\agent\_work\2\s\src\vctools\crt\vcruntime\src\eh\throw.cpp (133): _CxxThrowException
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\naudiodon\node_modules\node-addon-api\napi-inl.h (2572): Napi::FunctionReference::Call
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\naudiodon\src\audioio.cc (85): streampunk::WriteWorker::OnOK
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\naudiodon\node_modules\node-addon-api\napi-inl.h (73): Napi::details::WrapCallback<<lambda_f85feabe9509ada3892561e506fcfa4d> >
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\naudiodon\node_modules\node-addon-api\napi-inl.h (3838): Napi::AsyncWorker::OnWorkComplete
00007FF76CF3314C (node): (filename not available): node_module_register
00007FF76CFB7B40 (node): (filename not available): uv_timer_stop
00007FF76CFB7C17 (node): (filename not available): uv_timer_stop
00007FF76CFB463B (node): (filename not available): uv_async_send
00007FF76CFB3DDC (node): (filename not available): uv_loop_init
00007FF76CFB3FA4 (node): (filename not available): uv_run
00007FF76CEC63A1 (node): (filename not available): v8::internal::AsmJsScanner::GetIdentifierString
00007FF76CF390E3 (node): (filename not available): node::Start
00007FF76CDA6A9C (node): (filename not available): RC4_options
00007FF76DC2F8C8 (node): (filename not available): v8::internal::SetupIsolateDelegate::SetupHeap
00007FFF9D767BD4 (KERNEL32): (filename not available): BaseThreadInitThunk
00007FFF9E16CE51 (ntdll): (filename not available): RtlUserThreadStart
Error: Invalid argument
EXIT FUNCTION FIRING

Error when sending to devices which are only attached to speakers:

PID 15292 received SIGSEGV for address: 0x6d4770e7
SymInit: Symbol-SearchPath: '.;C:\Users\emina\OneDrive\Room\Subsystems\Host\node_server;C:\Program Files\nodejs;C:\WINDOWS;C:\WINDOWS\system32;SRV*C:\websymbols*http://msdl.microsoft.com/download/symbols;', symOptions: 530, UserName: 'emina'
OS-Version: 10.0.18363 () 0x100-0x1
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\segfault-handler\src\stackwalker.cpp (924): StackWalker::ShowCallstack
c:\users\emina\onedrive\room\subsystems\host\node_server\node_modules\segfault-handler\src\segfault-handler.cpp (242): segfault_handler
00007FFF9E1785B6 (ntdll): (filename not available): RtlIsGenericTableEmpty
00007FFF9E16A056 (ntdll): (filename not available): RtlRaiseException
00007FFF9E19FE3E (ntdll): (filename not available): KiUserExceptionDispatcher
00007FF76D4770E7 (node): (filename not available): v8::internal::JSObject::AddDataElement
00007FF76D43539F (node): (filename not available): v8::internal::PrototypeUsers::Add
00007FF76D4501FD (node): (filename not available): v8::internal::Object::SetProperty
00007FF76D72577A (node): (filename not available): v8::Object::Set
00007FF76CF84E39 (node): (filename not available): node::CallbackScope::CallbackScope
00007FF76CF84BB7 (node): (filename not available): node::CallbackScope::CallbackScope
00007FF76CF85CC4 (node): (filename not available): node::AsyncResource::CallbackScope::CallbackScope
00007FF76CF330FE (node): (filename not available): node_module_register
00007FF76CFB7B40 (node): (filename not available): uv_timer_stop
00007FF76CFB7C17 (node): (filename not available): uv_timer_stop
00007FF76CFB463B (node): (filename not available): uv_async_send
00007FF76CFB3DDC (node): (filename not available): uv_loop_init
00007FF76CFB3FA4 (node): (filename not available): uv_run
00007FF76CEC63A1 (node): (filename not available): v8::internal::AsmJsScanner::GetIdentifierString
00007FF76CF390E3 (node): (filename not available): node::Start
00007FF76CDA6A9C (node): (filename not available): RC4_options
00007FF76DC2F8C8 (node): (filename not available): v8::internal::SetupIsolateDelegate::SetupHeap
00007FFF9D767BD4 (KERNEL32): (filename not available): BaseThreadInitThunk
00007FFF9E16CE51 (ntdll): (filename not available): RtlUserThreadStart```

About this issue

Most upvoted comments

I have made a big change to naudiodon in version 2.3.0. I have removed the node_addon_api dependency and ported the code to use the native node_api while keeping the interface unchanged. I am hopeful that this will fix the particular crashes that have been seen. I’ll leave the issue open for a while in case anyone has feedback.