Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #1547 for skater and shooter demos: Segfault after failed audio subsystem installation on Linux. #1566

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions demos/shooter/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,30 @@ static void move_everyone(void)
if ((key[ALLEGRO_KEY_UP])) { // || (joy[0].stick[0].axis[1].d1)) {
/* firing thrusters */
if (yspeed < MAX_SPEED) {
if (yspeed == 0) {
al_stop_sample(&engine);
al_play_sample(data[ENGINE_SPL].dat, 0.9, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0,
1.0, ALLEGRO_PLAYMODE_LOOP, &engine);
}
else {
/* fade in sample while speeding up */
ALLEGRO_SAMPLE_INSTANCE *si = al_lock_sample_id(&engine);
al_set_sample_instance_gain(si, yspeed * 64 / MAX_SPEED / 255.0);
al_set_sample_instance_pan(si, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0);
al_unlock_sample_id(&engine);
}
if (al_is_audio_installed()) {
if (yspeed == 0) {
al_stop_sample(&engine);
al_play_sample(data[ENGINE_SPL].dat, 0.9, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0,
1.0, ALLEGRO_PLAYMODE_LOOP, &engine);
}
else {
/* fade in sample while speeding up */
ALLEGRO_SAMPLE_INSTANCE *si = al_lock_sample_id(&engine);
al_set_sample_instance_gain(si, yspeed * 64 / MAX_SPEED / 255.0);
al_set_sample_instance_pan(si, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0);
al_unlock_sample_id(&engine);
}
}
yspeed++;
}
else {
/* adjust pan while the sample is looping */
ALLEGRO_SAMPLE_INSTANCE *si = al_lock_sample_id(&engine);
al_set_sample_instance_gain(si, 64 / 255.0);
al_set_sample_instance_pan(si, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0);
al_unlock_sample_id(&engine);
if (al_is_audio_installed()) {
/* adjust pan while the sample is looping */
ALLEGRO_SAMPLE_INSTANCE *si = al_lock_sample_id(&engine);
al_set_sample_instance_gain(si, 64 / 255.0);
al_set_sample_instance_pan(si, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0);
al_unlock_sample_id(&engine);
}
}

ship_burn = TRUE;
Expand All @@ -161,17 +165,19 @@ static void move_everyone(void)
/* not firing thrusters */
if (yspeed) {
yspeed--;
if (yspeed == 0) {
al_stop_sample(&engine);
}
else {
/* fade out and reduce frequency when slowing down */
ALLEGRO_SAMPLE_INSTANCE *si = al_lock_sample_id(&engine);
al_set_sample_instance_gain(si, yspeed * 64 / MAX_SPEED / 255.0);
al_set_sample_instance_pan(si, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0);
al_set_sample_instance_speed(si, (500 + yspeed * 500 / MAX_SPEED) / 1000.0);
al_unlock_sample_id(&engine);
}
if (al_is_audio_installed()) {
if (yspeed == 0) {
al_stop_sample(&engine);
}
else {
/* fade out and reduce frequency when slowing down */
ALLEGRO_SAMPLE_INSTANCE *si = al_lock_sample_id(&engine);
al_set_sample_instance_gain(si, yspeed * 64 / MAX_SPEED / 255.0);
al_set_sample_instance_pan(si, -1 + 2 * PAN(player_x_pos >> SPEED_SHIFT) / 255.0);
al_set_sample_instance_speed(si, (500 + yspeed * 500 / MAX_SPEED) / 1000.0);
al_unlock_sample_id(&engine);
}
}
}

ship_burn = FALSE;
Expand Down Expand Up @@ -343,7 +349,10 @@ void play_game(void)

/* introduction synced to the music */
draw_intro_item(INTRO_BMP_1, 5);
play_midi(data[GAME_MUSIC].dat, TRUE);

if (al_is_audio_installed())
play_midi(data[GAME_MUSIC].dat, TRUE);

clear_keybuf();

if (fade_intro_item(-1, 2))
Expand Down Expand Up @@ -447,7 +456,8 @@ void play_game(void)
}

/* cleanup */
al_stop_sample(&engine);
if (al_is_audio_installed())
al_stop_sample(&engine);

while (bullet_list)
delete_bullet(bullet_list);
Expand Down
6 changes: 4 additions & 2 deletions demos/shooter/title.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,10 @@ int title_screen(void)
text_pix = 0;
text_width = 0;

play_midi(data[TITLE_MUSIC].dat, TRUE);
play_sample(data[WELCOME_SPL].dat, 255, 127, 1000, FALSE);
if (al_is_audio_installed()) {
play_midi(data[TITLE_MUSIC].dat, TRUE);
play_sample(data[WELCOME_SPL].dat, 255, 127, 1000, FALSE);
}

load_credits();

Expand Down
4 changes: 3 additions & 1 deletion demos/skater/src/framework.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ int init_framework(void)
sound or music (or both). */
al_install_audio();
al_init_acodec_addon();
al_reserve_samples(8);

if (al_is_audio_installed())
al_reserve_samples(8);

event_queue = al_create_event_queue();

Expand Down
10 changes: 8 additions & 2 deletions demos/skater/src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,20 @@ static void GenericInit(void)
WaterVoice = al_create_sample_instance(WaveNoise);
al_set_sample_instance_playmode(WaterVoice, ALLEGRO_PLAYMODE_BIDIR);
al_set_sample_instance_gain(WaterVoice, 0.5);
al_attach_sample_instance_to_mixer(WaterVoice, al_get_default_mixer());

if (al_is_audio_installed())
al_attach_sample_instance_to_mixer(WaterVoice, al_get_default_mixer());

al_play_sample_instance(WaterVoice);

WaterVoice2 = al_create_sample_instance(WaveNoise);
al_set_sample_instance_playmode(WaterVoice2,
ALLEGRO_PLAYMODE_BIDIR);
al_set_sample_instance_gain(WaterVoice2, 0.25);
al_attach_sample_instance_to_mixer(WaterVoice2, al_get_default_mixer());

if (al_is_audio_installed())
al_attach_sample_instance_to_mixer(WaterVoice2, al_get_default_mixer());

al_play_sample_instance(WaterVoice2);

play_music(DEMO_MIDI_INGAME, true);
Expand Down