SFML community forums

Help => Audio => Topic started by: Mark on December 12, 2013, 03:43:41 pm

Title: Audio variables cause main function to return an incorrect value!
Post by: Mark on December 12, 2013, 03:43:41 pm
This code works right:
#include <SFML/Audio.hpp>
int main()
{
      return 0;
}
And this one...
#include <SFML/Audio.hpp>
sf::Sound sound; /// <--- Note the change!
int main()
{
      return 0;
}
returns a value of -2147418113 instead of 0.
Any ideas why is this happening?
Title: Re: Audio variables cause main function to return an incorrect value!
Post by: Nexus on December 12, 2013, 03:49:15 pm
Does it happen when you declare the variable locally?

Don't use global variables, especially not with SFML types, because you can mess up internal initialization/destruction order. In general, it's good practice to avoid global variables. Well-designed code doesn't need them.
Title: Re: Audio variables cause main function to return an incorrect value!
Post by: Mark on December 12, 2013, 03:53:02 pm
I'll take your advice for further development. Moved the variables to the main function. Same wrong return value.
Title: Re: Audio variables cause main function to return an incorrect value!
Post by: Nexus on December 12, 2013, 04:41:44 pm
Did you link everything correctly (double-check the tutorial)? Are you sure the audio DLLs (OpenAL32, libsndfile1) provided by SFML and not pre-installed ones are used?
Title: Re: Audio variables cause main function to return an incorrect value!
Post by: Mark on December 12, 2013, 05:46:44 pm
Not exactly like in tutorial, but I know it should work anyways.
1. All these *.dlls are in system32 so I shouldn't move them everytime I make a new project. When I'll export the final release version of a program I'll ship it with the *.dlls it needs. No previous versions of SFML are installed. The version of this SFML is correct for my GCC compiler (otherwise it would complain and the program couldn't start, right?).
(http://i.imgur.com/yffhy6q.gif)
2. All the following settings are in the global compiler settings so I shouldn't reset them every time I start a new project. Don't worry, the same settings in the project compiler settings are set blank, for both releases. No other settings or flags in global compiler settings, only the default ones.
(http://i.imgur.com/0IguIiX.gif)
(http://i.imgur.com/cNDk6Js.gif)
(http://i.imgur.com/0UdTNJ0.gif)
Nothing more. Nothing additional. Only these settings were changed.
P.S. I'm running win32 on a 64 bit machine. Might that be the case?
Title: Re: Audio variables cause main function to return an incorrect value!
Post by: wintertime on December 13, 2013, 11:11:38 pm
I think the return value you see is not actually returned by your program. Thats some exception/seg-fault converted to a number by the code-blocks runner and there normally should be some text in the console window to indicate this, but if you dont let it show one you are out of luck. Thats why its better if you have the project set to show the console window when debugging.
Are you sure you downloaded the right library files for your compiler? If its the compiler that came with code::blocks you need the libraries for TDM-gcc.
Something unrelated, but that may be a problem later is you may need to sort the link libraries in the order of dependent libraries first, then more general libraries (audio depends on system, graphics on window, window on system).
Btw., you also should not have put the dll files into system32, because adding the bin directory to the path environment variable would have been enough and easier if you need another version of a library.