sorry for the english, I'm brazilian and I need help ...
ALLEGRO_SAMPLE_ID always the id is returning -1
I stated the ALLEGRO_SAMPLE_ID in a header and I am trying to access it in another. cpp but it always returns the id - 1
I'll post the part of the code here:
.h
ALLEGRO_SAMPLE_ID teste;
.cpp
al_play_sample(sample_cowboys, 1, 0, 1, ALLEGRO_PLAYMODE_LOOP, &teste);
al_stop_sample(&teste); // that part of the runtime error!!
help me please!
You probably didn't call al_reserve_samples, or called it with too small a number. Also, you should check that al_play_sample returns true before you use the ALLEGRO_SAMPLE_ID for anything.
i'm calling al_reserve_samples (1);
al_play_sample is returning true
I tried to increase the number of al_reserve_samples but not solved
code
al_reserve_samples(10);
sample_cowboys = al_load_sample("aud/teste.ogg");
Did you also call al_install_audio and al_init_acodec_addon?
EDIT: If you declare a variable in a header, you have to put extern in front of it, to avoid getting multiple definitions.
// Declare in a header: extern ALLEGRO_SAMPLE_ID teste; // Define in a single cpp: ALLEGRO_SAMPLE_ID teste;
Then it can be used in every .cpp file that included the header with the declaration.
yes, my only problem is the ALLEGRO_SAMPLE_ID the moment I use al_stop_sample.
EDIT
the ALLEGRO_SAMPLE_ID this in a class
And you are sure that viewInit is actually constructed before viewGame? It's hard to tell when you only post snippets of code...
EDIT
I'm looking at the source of al_play_sample and I don't see any way that it can return true while at the same time setting the id parameter to -1; Try making a small test case that illustrates the bug I guess.