我有一个项目是重新编码Bomberman,我实现了sf :: Music for music添加到主菜单,但我遇到了一个错误:
AL lib: (EE) alc_cleanup: 1 device not closed
它依赖于此: void * pthreadSound(void *);
int main(int, char **){
GameEngine *game = new GameEngine();
pthread_attr_t attr;
pthread_t sound;
void *retval;
try {
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (!game->initialize())
throw ErrorBomberman("Game fail initialisation", "main");
game->m_mutex = PTHREAD_MUTEX_INITIALIZER;
game->setLock(true);
pthread_create(&sound, &attr, pthreadSound, (void *)game);
game->ChangeState(IntroState::Instance());
while (game->Running()){
game->HandleEvents();
game->update();
game->draw();
}
game->Cleanup();
pthread_join(sound, &retval);
} catch (ErrorBomberman const &e) {
std::cerr << "Error caught in " << e.getComponent() << ": " << e.what() << std::endl;
}
return (EXIT_SUCCESS);
}
void *pthreadSound(void *game){
sf::Music music1;
if (!music1.OpenFromFile("./ressources/Bomberman_Theme.ogg"))
std::cout << "Erreur : load" << std::endl;
music1.Play();
while (((GameEngine *)game)->getLock()){
}
std::cout << "Stop" << std::endl;
music1.Stop();
pthread_exit(NULL);
return (NULL);
}
也许,这是因为Stop不起作用?我不知道。如果您有任何想法,谢谢。
答案 0 :(得分:0)