Sound problems

Here I have a simple part of a code:

1(...) 2ALLEGRO_SAMPLE *song = NULL; 3ALLEGRO_SAMPLE_ID* SWITCH; 4(...) 5song = al_load_sample("DATA/SOUND/GoGo.ogg"); 6 if(!song){ 7 fprintf(stderr, "failed to create sound 3!\n"); 8 } 9(...) 10al_play_sample(song, 0.8, 0, 1, ALLEGRO_PLAYMODE_LOOP, SWITCH); 11(...)

On my laptop it works perfectly. The music plays and stops when it should, but on my PC the game crashes on al_play_sample(). When I delete the sample_id part(or turn off the music by the game menu) it works fine, but i can't stop the music ><".

Matthew Leverton
al_play_sample(song, 0.8, 0, 1, ALLEGRO_PLAYMODE_LOOP, &SWITCH);


Thank you. And can you explain me shortly why it's this way?

Matthew Leverton

Allegro assumes you have already reserved the space for the sample id, so you need to pass it a pointer that points to a valid block of memory.

ALLEGRO_SAMPLE_ID foo; // reserves space
ALLEGRO_SAMPLE_ID *fooptr; // points to some arbitrary location

Thread #609536. Printed from