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

Author Topic: Trouble with sf::Music  (Read 6117 times)

0 Members and 2 Guests are viewing this topic.

zzzzlzzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Trouble with sf::Music
« on: August 27, 2015, 01:12:34 pm »
Hello, i write simple game with SFML.
I using sf::Sound and all is ok. If i use sf::Music periodically i get error in console:

(click to show/hide)

My code:

(click to show/hide)

Please, tell me where my mistake. And sorry for my bad english.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Trouble with sf::Music
« Reply #1 on: August 27, 2015, 01:22:32 pm »
What is musicPlayer?

You should read this article. It's really important. Most specifically, this part.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

zzzzlzzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Trouble with sf::Music
« Reply #2 on: August 27, 2015, 06:54:35 pm »
Thanks for reply!

The my demo code is:

(click to show/hide)

If i run this without creating window - all ok (infinite loop). I think, trouble generated in call sf::Music::play (may be i wrong).

I use SFML from git and from official site.
My OS: Windows 7 x64
My IDE: Visual Studio 2013
I build x32 application and x32 version sfml.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Trouble with sf::Music
« Reply #3 on: August 27, 2015, 10:32:19 pm »
What is the problem you're having with it?

This code compiles and starts playing the music.


EDIT:
It looks like you forgot to use musicLength to represent the music's duration. Doesn't look like it's needed though...

Why are you using curLength to keep track of the position in the music when sf::Music has getPlayingOffset()?

Moreover, why use that to see if the music has finished? Why not, instead, use getStatus() to test if it has finished playing?

Why are you using using namespace sf and using namespace std and specifying (sometimes) the sf:: and std:: prefixes? Just remove the "using namespace"s, add the prefixes and stop being lazy  :-X
« Last Edit: August 27, 2015, 10:47:40 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

zzzzlzzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Trouble with sf::Music
« Reply #4 on: August 28, 2015, 11:15:10 am »
My current code:
(click to show/hide)
My problem shown sometimes. In console shown messages (in first post) and music not played. And next program crashed. Many run my program work fine.
I don't understand reasons error.

Maybe, main reasons - it is my OS? I use OpenAL from distributibe SFML.

P.S. Messages show in console asynchronously. Sometimes message crossed. (exmpl. An internal iled in SoundSource.cpp(177) OpenAL call failed in SoundSource.cpp(177).)

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Trouble with sf::Music
« Reply #5 on: August 28, 2015, 01:40:24 pm »
it is my OS?
I don't think so. My set up seems identical.

I use SFML from git and from official site.
Just noticed this that you posted earlier. You said "from git and official site." What does this mean?
Have you tried both? If so, it's possible that you may be mixing libraries. e.g. using DLLs from a different version to the code you're including.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

zzzzlzzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Trouble with sf::Music
« Reply #6 on: August 28, 2015, 02:23:50 pm »
About dll: i test my code with version on sfml-dev (and his dll), and with version on git (and his dll). I make this for get more detailed error report.

I don't know how repeat condition for generation my problem, and very strange that my problem generated sometimes.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Trouble with sf::Music
« Reply #7 on: August 28, 2015, 02:29:05 pm »
I'm not certain what you mean by "problem". Is the problem that error codes and the eventually crashing, or are there artifacts in the sound/sound doesn't play?

How does it crash? What messages do you get? Where in the code does it stop?

Are you building in debug or release mode? Are the problems the same in both?

The more information you can provide about the actual problem could help a lot.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

zzzzlzzzz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Trouble with sf::Music
« Reply #8 on: August 28, 2015, 04:12:50 pm »
I test my game in two case: use precompiled sfml and use git version.
If i use precompiled version game not play music, show message in console, and crashed because stack overflow. Messages similar to git version messages, but short (show source file, line number and short error type (exmpl.  AL_INVALID_OPERATION))
If i use git version game not play music and show message in console (first post).
It happened sometimes in debug version. In release all ok.

After i recompile all project file and library problem gone. I'm not sure that it's solving my problem, but program working.