Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Weird segmentation fault  (Read 27762 times)

0 Members and 1 Guest are viewing this topic.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Weird segmentation fault
« on: June 12, 2008, 03:25:30 am »
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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Weird segmentation fault
« Reply #1 on: June 12, 2008, 05:57:01 am »
Sorry, no idea. This is really weird :|

What does the call stack show between your own functions and the OpenAL ones (ie the SFML functions) ?
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Weird segmentation fault
« Reply #2 on: June 14, 2008, 02:07:05 am »
I'm very sorry -- the problem was a pointer going to nowhere. ;) It was hard to find and caused the segmentation fault on a completely other location than suggested.

So SFML works very fine. :-) Anyways, thank you for your help and keep up the very good work guys.

 

anything