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

Author Topic: Audio variables cause main function to return an incorrect value!  (Read 3274 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Guest
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.
  • This happens when I insert any audio variable (would it be buffer, sound or music).
  • It doesn't happen when I insert any other variable of other SFML module.
  • Despite the wrong return value of main function sounds and music play correctly.
  • Windows 7 Ultimate, Code::Blocks 12.11 IDE, release configuration, GCC, no optimization flags.
Any ideas why is this happening?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Audio variables cause main function to return an incorrect value!
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Mark

  • Guest
Re: Audio variables cause main function to return an incorrect value!
« Reply #2 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.
« Last Edit: December 12, 2013, 04:00:34 pm by Mark »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Audio variables cause main function to return an incorrect value!
« Reply #3 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?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Mark

  • Guest
Re: Audio variables cause main function to return an incorrect value!
« Reply #4 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?).

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.



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?

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: Audio variables cause main function to return an incorrect value!
« Reply #5 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.

 

anything