SFML community forums

Help => Audio => Topic started by: Mike__ on July 11, 2014, 11:01:31 am

Title: sf::Listener. The app doesn't respond.
Post by: Mike__ on July 11, 2014, 11:01:31 am
Hello. I use SFML 2.1 inside teamspeak plugin.
I used sf::Sound object like in tutorials.
sf::Sound sound;
The plugin could not be initialised. The application didn't respond.
Ok, I've solved it:
sf::Sound* sound;
...

int ts3plugin_init() {
    sound = new sf::Sound();
    ...
}
After this the application can initialize the plugin successfully and it works properly. (SFML is a very good thing).

But.
If i use sf::Listener in any place of my plugin then teamspeak cannot unload this plugin. It doesn't respond.
If I remove all sf::Listener call then teamspeak can unload plugin properly.
I can't use pointer on sf::Listener object because it has static methods only.
Can you help me?

Upd:
I suppose it happens because:
void ensureALInit()
{
    // The audio device is instantiated on demand rather than at global startup,
    // which solves a lot of weird crashes and errors.
    // It is destroyed at global exit which is fine.

    static AudioDevice globalDevice;
}
 
Title: Re: sf::Listener. The app doesn't respond.
Post by: zsbzsb on July 11, 2014, 12:42:39 pm
Not sure exactly what you are asking, but it seems to be related to you using global objects. When using SFML (and in most other cases) it is a very good idea to avoid using global variables as they will cause issues (as seems to be the case here).
Title: Re: sf::Listener. The app doesn't respond.
Post by: Mike__ on July 11, 2014, 01:15:41 pm
The plugin based on callback functions and I can't avoid global objects at all.

But the problem is if I use sf::Listener then teamspeak can't unload plugin.

in other words:
If I will write only one SFML row:
sf::Listener::setPosition(5.f, 0.f, 5.f);
Then teamspeak will not be able to unload plugin with this row. If I will delete this row then all will works fine.
Title: Re: sf::Listener. The app doesn't respond.
Post by: Laurent on July 11, 2014, 01:47:59 pm
You should try to compile this branch, it changes the way the audio context is managed by SFML and may solve your problems.

https://github.com/SFML/SFML/tree/bugfix/al_context
Title: Re: sf::Listener. The app doesn't respond.
Post by: Mike__ on July 12, 2014, 08:56:34 am
I couldn't use this branch cause I got incorrect static (*-s.lib) files (there was linking error while compiling plugin).
But I've solved my problem this way(SFML 2.1 sources fast fix):

AudioDevice* globalDevice = NULL;
void ensureALInit()
{
        if(globalDevice == NULL){
                globalDevice = new AudioDevice();
        }
}

void aLEnd()
{
                globalDevice->~AudioDevice();
                globalDevice = NULL;
}

I call aLEnd function manually before plugin unloading. In this case I can reload plugin properly.
Title: Re: sf::Listener. The app doesn't respond.
Post by: Laurent on July 12, 2014, 09:28:27 am
This is wrong, you should call "delete globalDevice", not just the destructor (otherwise the memory is never deallocated).

But what's your problem with the branch? Whay do you say the lib files were incorrect?
Title: Re: sf::Listener. The app doesn't respond.
Post by: Mike__ on July 12, 2014, 09:56:17 am
This is wrong, you should call "delete globalDevice", not just the destructor (otherwise the memory is never deallocated).
I missed it. Thanks.


If I use sfml-system-s.lib and sfml-audio-s.lib from this branch then I got while plugin compiling:
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alSourcePause"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alGetSourcef"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alGetSourcef"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alSourceQueueBuffers"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alBufferData"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alSourceUnqueueBuffers"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alGetSourcei"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alGetSourcei"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alSourcePlay"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alDeleteBuffers"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alSourcei"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alSourcei"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alSourceStop"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alGetBufferi"
1>sfml-audio-s.lib(SoundStream.obj) : error LNK2001: unresolved external symbol "__imp__alGenBuffers"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alGenSources"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alDeleteSources"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alSourcef"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alSource3f"
1>sfml-audio-s.lib(SoundSource.obj) : error LNK2001: unresolved external symbol "__imp__alGetSource3f"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alcCloseDevice"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alcDestroyContext"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alcMakeContextCurrent"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alListenerf"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alListener3f"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alListenerfv"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alcCreateContext"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alcOpenDevice"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alGetEnumValue"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alIsExtensionPresent"
1>sfml-audio-s.lib(AudioDevice.obj) : error LNK2001: unresolved external symbol "__imp__alcIsExtensionPresent"

Title: Re: sf::Listener. The app doesn't respond.
Post by: Nexus on July 12, 2014, 10:22:55 am
Define SFML_STATIC. When you link statically, you also have to link SFML's dependencies (such as OpenAL) explicitly.
Title: Re: sf::Listener. The app doesn't respond.
Post by: Mike__ on July 12, 2014, 10:27:07 am
I use it.

SFML alContext:
WIN32;_WINDOWS;NDEBUG;SFML_STATIC;_CRT_SECURE_NO_DEPRECATE;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)

plugin:
SFML_STATIC;WIN32;NDEBUG;_WINDOWS;_USRDLL;PLUGIN2_EXPORTS;QT_THREAD_SUPPORT;QT_CORE_LIB;QT_GUI_LIB;%(PreprocessorDefinitions)

upd:
I can't use sfml-audio-s.lib in alContext branch compilation, but v2.1 works for me.
Title: Re: sf::Listener. The app doesn't respond.
Post by: Nexus on July 12, 2014, 10:56:55 am
Read my edit ;)

The linking has changed after 2.1, now you have to do it manually for static libraries.
Title: Re: sf::Listener. The app doesn't respond.
Post by: Mike__ on July 12, 2014, 11:23:46 am
Is that means I have to compile SFML dependents as static lib too?

Can you give me an example or short manual on it?
Title: Re: sf::Listener. The app doesn't respond.
Post by: Nexus on July 12, 2014, 11:43:55 am
No, but you must link them.

https://github.com/SFML/SFML/wiki/FAQ#build-link-static
Title: Re: sf::Listener. The app doesn't respond.
Post by: Mike__ on July 12, 2014, 12:15:44 pm
Ok, I understood.
Thanks for your help.