Allegro Crashes With USB Audio Attached and Set as Default...
Matt Dralle


I've been using Allegro 5 successfully on my Raspberry PI 4 (now Odroid C4) in a pure C project. However, I recently added a USB sound bar, which is otherwise working fine on the system. It shows up as "Card 1" with an "aplay -l":

Odroid Root [AllegroTest] ==> aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ODROIDHDMI [ODROID-HDMI], device 0: SPDIF-dit-hifi dit-hifi-0 []
Subdevices: 0/1
Subdevice #0: subdevice #0
card 1: Device [USB2.0 Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

In /etc/asound.config I changed "card 0" to "card1" to to force the USB to be default sound source with:

pcm.!default {
type hw card 1
ctl.!default {
type hw card 1

amixer works fine with this setup:

amixer -c 1 cset numid=3 100

mplayer also works fine with this setup:

mplayer -ao alsa:device=default "

However Allegro always crashes hard with this setup. Here is the function I am calling, gdb indicates the crash is happening at the line:

"al_attach_sample_instance_to_mixer(sampleInstance, al_get_default_mixer() );"

This is my function to setup and play my sounds (Sounds[ SoundsIndex ].SoundObject):

void PlaySound( unsigned int SoundsIndex )

sampleInstance = al_create_sample_instance( Sounds[ SoundsIndex ].SoundObject );
al_attach_sample_instance_to_mixer(sampleInstance, al_get_default_mixer() );
al_rest( Sounds[ SoundsIndex ].Length );

I tried the latest version of the Allegro distribution. I'm really at a loss as what to try next to fix this. I've tried four different USB speakers, all behave the same.

If I set "hw card 1" to "hw card 0" in /etc/asound.conf, no allegro crashes, sound works through HDMI/SPDIF.

Please help, I'm stumped...

Thank you,

Matt Dralle

Peter Hull

Can you get a full back-trace from GDB?
The crash in your code is in "al_attach_sample_instance_to_mixer(sampleInstance, al_get_default_mixer() );" but it's not clear from that, where in Allegro's internal code the crash might be.

Matt Dralle

Here's the full gdb output at the crash including a "where"...

[New Thread 0x7faeffcd80 (LWP 61726)]

(leopard:61698): GLib-GIO-CRITICAL **: 11:12:52.009: g_dbus_proxy_new: assertion 'G_IS_DBUS_CONNECTION (connection)' failed

Thread 6 "leopard" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7faeffcd80 (LWP 61726)]
al_attach_sample_instance_to_mixer (spl=spl@entry=0x7fa0000b60, mixer=0x0) at /usr/local/src/allegro/addons/audio/kcm_mixer.c:692
692 bool al_attach_sample_instance_to_mixer(ALLEGRO_SAMPLE_INSTANCE *spl,
(gdb) where
#0 al_attach_sample_instance_to_mixer (spl=spl@entry=0x7fa0000b60, mixer=0x0) at /usr/local/src/allegro/addons/audio/kcm_mixer.c:692
#1 0x0000005555570220 in PlaySound (SoundsIndex=1) at Sound.c:121
#2 PlaySound_Chimes (peram=<optimized out>) at Sound.c:149
#3 0x0000007fb763b4fc in start_thread (arg=0x7fffffef9f) at pthread_create.c:477
#4 0x0000007fb759467c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

Edgar Reynaldo

If you look in the backtrace you can see that the pointer is null for the mixer you're attaching it to.

Look at the mixer creation it is returning null. Perhaps you passed it bad parameters.

al get default mixer will only return true if you've created a hardware voice.

Matt Dralle

Is the another call to init the mixer?

I'm calling the following to setup Allegro up:

al_reserve_samples( MAX_SOUND_COUNT );

In my "al_attach_sample_instance_to_mixer(sampleInstance, al_get_default_mixer() );":

Why does the call to "al_get_default_mixer()" return NULL on the USB audio? Card 1 vs Card0



Peter Hull

I would start with the simplest possible program

#include <allegro5/allegro.h>
#include <allegro5/allegro_audio.h>
#include <stdio.h>

int main() {
  printf("Default mixer: %p\n", al_get_default_mixer());
  return 0;

and also create an allegro5.cfg in the same directory as the executable


Can you confirm this reproduces the problem, default mixer is NULL for hw card 1 and not NULL for hw card 0? If you look at the file allegro.log in both cases does it print anything helpful?

Edgar Reynaldo

Check the return value of al_reserve_samples(...) . Step into the function and see where the voices and mixers are created.

Did you ever learn how to debug? Now is the time, my young padawan.

Thread #618563. Printed from