C ++ Allegro停止了样本

问题描述 投票:-1回答:2

我想在某个时刻停止我的样本,但它给我发了一些奇怪的错误。这是我的代码:

ALLEGRO_SAMPLE_ID id;
ALLEGRO_SAMPLE* spl = al_load_sample("sound.ogg");
al_play_sample(spl, 1.0, 0, 1.0, 0, &id);
al_stop_sample(&id);
al_destroy_sample(spl)
c++ allegro5
2个回答
0
投票

正如here建议的那样,Allegro很可能在播放的对象试图阻止和破坏之前被摧毁了:

在你摧毁了所有东西后,你确定Allegro已经去了初始化吗?我通过将关闭代码放在atexit回调中但让Allegro注册一个自定义的atexit回调来遇到这个问题。在这种情况下,可能首先运行Allegro的atexit回调,因此您必须使用al_install_system(NULL,ALLEGRO_VERSION_INT)并在自定义atexit回调中调用al_uninstall_system(),而不是al_init()。


-1
投票

试试这个

ALLEGRO_SAMPLE_ID *id_sample = NULL;
id_sample = malloc(sizeof(ALLEGRO_SAMPLE_ID));
l_play_sample(sample, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_BIDIR, id_sample);
printf("id_sample %p\n", id_sample);
al_rest(2);
al_stop_sample(id_sample);
© www.soinside.com 2019 - 2024. All rights reserved.