PaAlsaStreamComponent errors, even when not using audio


I am running NAP on an Ubuntu 19.04 system, and everything compiles and runs just fine.

However, I notice that I get random crashes with the following message:

random-light-grid: src/hostapi/alsa/pa_linux_alsa.c:3636: PaAlsaStreamComponent_BeginPolling: Assertionret == self->nfds’ failed.`

I am using NAP 0.2.3 - an old version, I know, but this is what the original application was built with. The error is odd because as far as I understand it relates to ALSA (Linux sound card driver stuff) and yet the application does not use audio in any way (does not even include mod_napaudio).

Any ideas how to prevent this behaviour?


And now managed to get the same project compiling in NAP 0.3.0 and the same issue remains.

Worse, in fact, since now it crashes every time on startup and never manages to run further.


Are you including mod_napvideo by any chance? mod_napvideo makes use of audio to output sound. When video is included, audio is included with it. If you don’t need video you can possibly remove it?

I haven’t tested audio under ubuntu 19.04, as we officially only support 18.04 (LTS versions). I did find some references to your problem online: PaAlsaStreamComponent errors, even when not using audio

I’m finding a handful of references to the same assertion you are seeing in various audio application forums, but no one seems to have chased it to root cause yet. I did finally find a bug report filed directly against pulseaudio here.

Of particular interest in the bug report: “this happens only with Alsa (and 1.1.4), but does not happen with the older 1.1.3”. If you have any ability to roll back to an older ALSA release, it may work around the problem until the PulseAudio team gets to the bottom of it.


Ah, interesting! I’m going to check this out.

Indeed, the project does use mod_napvideo


I’m going to try to fix this in the thirdparty repo, following the patch done here:


Cool! Wonder if that solves your issue with ALSA / Portaudio. Linux and audio back-ends has (in my experience) never been really good or stable.

From what I can see the issue is related to pulling (recording) audio. A good fix could be to disable audio input completely. I just submitted a patch (nap_source) that lets you set the channel audio input count to 0, which in turn disables audio input completely.

You can configure the audio service using a 'config.json' file next to your executable. For example:

	"Objects" :
			"Type": "nap::audio::AudioServiceConfiguration",
			"mID": "AudioConfiguration",
			"InputChannelCount" : 0,
			"OutputChannelCount" : 2,
			"AllowChannelCountFailure" : false
			"Type": "nap::RenderServiceConfiguration",
			"mID": "RenderConfiguration",
			"Settings": {
				"HighDPIMode" : true,
				"DoubleBuffer" : true,
				"EnableMultiSampling" : true,
				"MultiSamples" : 4

As you can see I configured both the sound and render engine using 2 configuration objects. Right now you have to create the config.json file manually, but we want to embed it in Napkin for easy visual configuration later on.

setting the InputChannelCount to 0 should result in no audio input stream and a possible fix. That way you don’t have to remove video, since it only outputs stereo audio.


Ah yeah that totally fixed it! Thank you.


Oops, I spoke too soon. Seeing the error again, intermittently. For now I’m doing a build from source with the assertion commented out in the portaudio library.


Thanks for letting met know @steveb. Looping in @stijnvanbeek, since he is the audio expert around here. Might be worth considering updating the portaudio library if it is fixed in a newer version.


As an alternative solution, if you keep running into this issue with portaudio, I can create a separate module that deals with audio from video. This module would depend on video but video would not depend on audio. This allows you to split the two. Let me know what you think!


Frustratingly, I even went into the thirdparty repo and commented out the line src/hostapi/alsa/pa_linux_alsa.c:3636 in portaudio and rebuild a new package of NAP from source and I STILL get the assertion thrown, from the same line apparently. Is there something I’m missing about how to build clean from source including rebuilding third party libraries? (The -c flag doesn’t appear to help?)


So far, running with the config.json file as you suggested seems to be holding up.


The problem here is that you have to manually rebuild portaudio to remove the assertion, as it is linked in as a dll. Third party dependencies are built separate from source and brought in using cmake. If my solution holds up I would suggest using that one.

Naïvi generally builds and maintains the third party libraries, but if you want you can recompile portaudio yourself. The output should override the. dylib which is brought in as a third party dependency.

Otherwise I can separate the video module as mentioned above, this should definitely fix your problem