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

Author Topic: Build 1250 gives error with loading Audio  (Read 7185 times)

0 Members and 1 Guest are viewing this topic.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Build 1250 gives error with loading Audio
« on: October 28, 2009, 04:26:50 am »
I tried to run my game with Build 1250, and discovered something strange. When I try to load an Audio file, the console gives this error:
Failed to play audio stream : sound parameters have not been initialized (call Initialize first)
After that error is given, the program crashes. Does anyone have any ideas why this happens? I am on Ubuntu 9.04.
I use the latest build of SFML2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Build 1250 gives error with loading Audio
« Reply #1 on: October 28, 2009, 08:49:52 am »
Can you show the code?

Is it build 1250 of trunk, or sfml2 branch?
Laurent Gomila - SFML developer

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
The code
« Reply #2 on: October 28, 2009, 02:53:51 pm »
Quote from: "Laurent"
Can you show the code?

Is it build 1250 of trunk, or sfml2 branch?

Here is the piece of code that trys to load some Audio and fails:
Code: [Select]
#include <SFML/Audio.hpp>
sf::Music BGMusic;
int main(){
    if (BGMusic.GetStatus() != BGMusic.Playing){
        BGMusic.OpenFromFile("Title.ogg");
        BGMusic.SetLoop(false);
        BGMusic.Play();
    }
    while (BGMusic.GetStatus == BGMusic.Playing){
    }
}

The music can be found here.
It is the SFML2 Branch.
I use the latest build of SFML2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Build 1250 gives error with loading Audio
« Reply #3 on: October 28, 2009, 03:21:05 pm »
You shouldn't use globals. Globals get constructed before main() starts, and SFML is not yet properly initialized at that point.
Laurent Gomila - SFML developer

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Confused
« Reply #4 on: October 28, 2009, 03:38:16 pm »
Quote from: "Laurent"
You shouldn't use globals. Globals get constructed before main() starts, and SFML is not yet properly initialized at that point.
I need to use the sf::Music object throughout my entire project. In the actual program, it is defined in a file called Rooms.cpp, which does not contain main(), and the program works all the way up until I try to load the Music in Rooms.cpp. Everything else with SFML works, just not this music. I have always used globals with SFML, and they have always worked on Windows and Linux. Why would it stop working now? I understand that SFML is not properly initialized, but how else am I going to use the BGMusic instance throughout my program(specifically the functions in Rooms.cpp)?
I use the latest build of SFML2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Build 1250 gives error with loading Audio
« Reply #5 on: October 28, 2009, 03:50:39 pm »
Quote
I have always used globals with SFML, and they have always worked on Windows and Linux. Why would it stop working now?

Because I modified the initialization code internally.

Quote
I understand that SFML is not properly initialized, but how else am I going to use the BGMusic instance throughout my program(specifically the functions in Rooms.cpp)?

There are cleaner solutions to have objects globally available, without using global variables. If you have some time to spend thinking about it, I'm sure you can find a smarter design for managing these objects.

One more question: is "Failed to play audio stream..." the only message you get on the standard error output? There's nothing else before? Do you run your application in debug mode?
Laurent Gomila - SFML developer

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Build 1250 gives error with loading Audio
« Reply #6 on: October 29, 2009, 11:30:36 pm »
Quote from: "Laurent"
Quote
I have always used globals with SFML, and they have always worked on Windows and Linux. Why would it stop working now?

Because I modified the initialization code internally.

Quote
I understand that SFML is not properly initialized, but how else am I going to use the BGMusic instance throughout my program(specifically the functions in Rooms.cpp)?

There are cleaner solutions to have objects globally available, without using global variables. If you have some time to spend thinking about it, I'm sure you can find a smarter design for managing these objects.

One more question: is "Failed to play audio stream..." the only message you get on the standard error output? There's nothing else before? Do you run your application in debug mode?
Failed to play Audio stream is the only error I am getting, since the program crashes immediately after.
I do have an idea for an alternative design, and I have been working on it, but it will take a while. It'll make my code a lot neater(and smaller), and should work...
I use the latest build of SFML2

 

anything