Hi all,
today I discovered a really weird segmentation fault regarding the audio package (better say: OpenAL).
I'm currently writing a Tetris game which has a "state" mechanism. That means, the game is splitted into states, e.g. the menu, in-game, highscore table etc. This way I can load/unload resources and seperate everything in a clean way. These states are organized in classes.
Well, I've always been using musics in my menu and in-game states. Switching between them has never been a problem. When switching states, the following procedure is done:
- create the new state (i.e. an object of the proper state class)
- notify active state that we're about to leave it
- delete active state (means delete the class object)
- set active state to new created state
Of course, constructors and destructors get called correctly. And in my case, I do nothing in the constructors than initializing a reference to an sf::RenderWindow.
Today, I wrote a new highscore state, to display the highscores table. I haven't implemented any music yet -- other things were more important. Compiled, and chose "Highscores" from the menu state. Menu gets deleted, highscore state activated -- no problems here. But when switching from the highscore state back to the menu state (i.e. creating Menu object, deleting Highscore object, activate Menu object), a segmentation fault occures.
And it exactly happens when constructing the menu state object, where NOTHING is done besides initializing the sf::RenderWindow reference. After using gdb to debug a bit, its backtrace showed me a fault in one of the OpenAL libraries. I really wondered why that happened, and after playing around a bit, I just added a music to the highscore state. Then, when switching to the menu, the segmentation fault isn't there anymore.
Because this really is a VERY strange thing, I'm hoping that anybody has an idea. I neither deinitialize any audio stuff nor load/unload any other important stuff. The only thing I'm doing is delete a state and create a new one, which is highly non-SFML stuff. Only one reference gets initialized in the state contructors, nothing more.
Any ideas?