Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access Violation error in the destructor of sf::AudioDevice #30

Closed
fpoisson opened this issue Apr 22, 2011 · 60 comments
Closed

Access Violation error in the destructor of sf::AudioDevice #30

fpoisson opened this issue Apr 22, 2011 · 60 comments
Assignees
Milestone

Comments

@fpoisson
Copy link

Access Violation error occurs int the destructor of sf::AudioDevice on Windows XP SP3. It doesn't occur on Windows 7 and Windows Vista.

Here is the instruction pointed by the visual C++ 2008 debugger:

Code:

AudioDevice::~AudioDevice() 
{ 
    // Destroy the context 
    alcMakeContextCurrent(NULL); 
    if (audioContext) 
=>           alcDestroyContext(audioContext); 

    // Destroy the device 
    if (audioDevice) 
        alcCloseDevice(audioDevice); 
} 

The error can be reproduced with this simple code :

#include <SFML/Audio.hpp> 

int main() 
{ 
    sf::Sound Sound; 

    return EXIT_SUCCESS; 
} 

This problem was first discussed in this post of the french forum :
http://www.sfml-dev.org/forum-fr/viewtopic.php?t=3443

@ghost ghost assigned LaurentGomila Apr 22, 2011
@LaurentGomila
Copy link
Member

Which version of SFML? Which libraries (dynamic or static)? Are you sure that you use the openal32.dll file provided in the extlibs/bin directory?

@fpoisson
Copy link
Author

I use the dll versions of this SFML2's revision :

  • Revision: ad79328
  • Date: 15/04/2011 18:14:35
  • Message: Fixed recursive mutex lock in GlContext::Cleanup()

I use the openal32.dll file provided in the extlibs/bin/x86/ directory.

@fpoisson
Copy link
Author

With the statics versions (debug & release), the error doesn't occur.

@LaurentGomila
Copy link
Member

Ok, I know what's wrong. Thanks for your feedback.

@kevvo1288
Copy link

I am having the same problem in Windows 7.
Steps:

  1. Generate project using Cmake
  2. Build all Projects in Visual Studio 2010 (32 bit, assume from now on)
  3. Try to run pong - Can't find SFML dlls.
  4. Add SFML debug dlls to directory.
  5. Try to run pong - Can't find openAL32.dll
  6. Add openAl and libsnd dlls to directory.
  7. Try to run pong - crashes on alcDestroyContext(audioContext); (in AudioDevice::~AudioDevice() )
  8. Add resources directory (I am slow but thorough :) )
  9. Try to run pong - IT WORKS!!! Game plays just fine, sound happens, etc...
  10. Press escape to quit pong - crashes on alcCloseDevice(audioDevice); (in AudioDevice::~AudioDevice() )

Same issue: It crashes in the deconstructor, although the exact line it fails on depends on whether or not the context has been created.

I'm free to experiment if there is a fix you'd like to try. I have the SFML git repo separate from the output from Cmake.

@LaurentGomila
Copy link
Member

Thanks for your feedback. Like I said previously, I know what's wrong and I'll fix it soon.

@dvoid
Copy link

dvoid commented Jun 13, 2011

been quiet here for a while, Any news about this bug? i really really need a fix as soon as possible. tanks

@LaurentGomila
Copy link
Member

As you can see, it's planned for SFML 2.x, not 2.0. So it's not the top priority, sorry.

@gchatelet
Copy link

Laurent can you explain a bit more on "Ok, I know what's wrong", so we can have a look and maybe submit a patch at some point ? I'm also running into this issue.

@LaurentGomila
Copy link
Member

Yeah, it's simple: the AudioDevice instance is destroyed at global exit.

@yadurajiv
Copy link

If I don't use the openal32.dll that came with sfml2, this error does not seem to happen. The latest OpenAL32.dll loads up slow, but it does not crash on exit.

@LaurentGomila
Copy link
Member

The latest OpenAL32.dll loads up slow, but it does not crash on exit.

The latest OpenAL32.dll from where?

@yadurajiv
Copy link

@LaurentGomila
Copy link
Member

As far as I know, this version is not updated anymore.

Updated Summer 2009 : Version 2.0.7.0

@yadurajiv
Copy link

hmm.. But strangely enough it works, for the time being. What codebase is the openal32 in the extlibs based on?

@LaurentGomila
Copy link
Member

The only implementation that is maintained and used everywhere now is OpenAL-Soft.

@yadurajiv
Copy link

yup, the binaries here - http://kcat.strangesoft.net/openal.html gives the error, which means we are back at square one _ sighs

@Ceylo
Copy link
Contributor

Ceylo commented Apr 7, 2012

I've got a similar crash on Windows 7 but on alcCloseDevice(audioDevice); in my project (different code). The sample code provided here to reproduce the bug correctly produces alcDestroyContext() bug though.

However the 1.14 DLL provided at http://kcat.strangesoft.net/openal.html#download fixes both my crash and the one quoted in this issue (NB: in the readme they say the provided OpenAL binary isn't redistributable).

Note that the 1.14 release is 9 days old.

@matpow2
Copy link

matpow2 commented Apr 12, 2012

Even with the 1.14 OpenAL-Soft DLL, I was getting crashes on Windows XP 32bit SP3. I managed to fix the issue by removing SFML's AudioDevice deconstructor. It seems like OpenAL-Soft uses an atexit deconstructor to clean up after itself, which is the case with SFML's AudioDevice deconstructor too. This probably leads to OpenAL/SFML trying to deinitialize stuff that's already been destroyed.

@GatorQue
Copy link

GatorQue commented Jul 7, 2012

@matpow2
When I use 1.14 OpenAL-Soft DLL my crashes went away, perhaps you were picking up an older version somewhere else on your computer?

@germinolegrand
Copy link

I have the same problem, with crashes very often. I can't wait any longer, any advice before i go and try to fix it myself ?

@germinolegrand
Copy link

The fix I did is actually a partial fix, there are no more crashes, but a lot of warnings in the console instead (not really a problem, but i don't like seeing warnings it means some errors might occur later). I will try to investigate later.

@LaurentGomila
Copy link
Member

Until you fix your fix (the diff shows all the files being completely changed -- probably due to different line breaks), there's no way to know what you did...

@Oberon00
Copy link
Contributor

You can append &w=1 to the commit URL to see only non-whitespace changes.

@LaurentGomila
Copy link
Member

Rather ?w=1 since the commit URL has no other argument ;)

So according to what I see, you moved the AudioDevice class from private to public. How does that solve anything?

@manolismi
Copy link

For me it didn't! This bug needs to be fixed soon, because every application that uses audio crashes! Hell, you can't distribute applications that crash! Because of mine application being fullscreen, when you click a button i made for closing the application, it freezes! The segmation error window pops behind the game and is not shown! And unless you click ok on it, the application can't close! But you can't click it because you don't see it! So reboot is the only option!

@manolismi
Copy link

Anyways, is there something that I can do that fixes it? If yes, please explain. Thank you very much, SFML is great and it is a pity that this bug is harassing my first game experience.

@binary1248
Copy link
Member

Use this experimental branch and see if it fixes the problem (it should). It might get merged at some point, but don't hold your breath.

@manolismi
Copy link

Thanks for replying, can you explain to me though what exactly I need to do? Replace the files by the corresponding experimentals?

@binary1248
Copy link
Member

Just download the zip and pretend you got it instead of the original SFML files. Of course you will have to build it yourself since there are no pre-compiled versions of branches.

@manolismi
Copy link

I don't know how to build it! I read the tutorial building with cmake but I can't do it. I have mingw and dev c++ 5.6.3 IDE

@PatrickTorgerson
Copy link

hey manolismi, I have a working build for codeblocks and visual studio express 2013, both of wich dont have this problem if you want to switch to one ill send you one.

@ghost
Copy link

ghost commented Jun 23, 2014

binary1248, Thanks a lot!!! This branch really fixes this annoying bug!!! Can't wait to see this branch merged into master! =)

@mantognini
Copy link
Member

@manolismi if you have a specific issue with cmake even after following 1:1 the tutorial and looking online for known solutions, you can ask for help on the forum (it's more appropriate there than here).

@manolismi
Copy link

Binary1248 I'm so grateful for your branch! Everything works! I can't thank you enough everyone, for your kindness and being helpful and supportive, even though I've spammed you a lot.

binary1248 added a commit that referenced this issue Jul 4, 2014
… context management. OpenAL contexts now only exist as long as AlResources require them and are destroyed when they are no longer required. Fixes #30.
binary1248 added a commit that referenced this issue Jul 12, 2014
… context management. OpenAL contexts now only exist as long as AlResources require them and are destroyed when they are no longer required. Fixes #30.
binary1248 added a commit that referenced this issue Aug 28, 2014
… context management. OpenAL contexts now only exist as long as AlResources require them and are destroyed when they are no longer required. Fixes #30.
@Ceylo
Copy link
Contributor

Ceylo commented Sep 25, 2014

As binary1248 seems to have fixed the issue, is it considered resolved?

@LaurentGomila
Copy link
Member

It's in a branch that is not merged (tested) yet, so no. It will be marked as resolved after being merged into master.

@Ceylo
Copy link
Contributor

Ceylo commented Sep 25, 2014

Ok. I couldn't find on which branch the commit was :)

@binary1248
Copy link
Member

@ghost
Copy link

ghost commented Oct 11, 2014

How much time will this take to get merged in master?
Got the same problem and it's kind of annoying...

@Bromeon
Copy link
Member

Bromeon commented Oct 11, 2014

As you see the milestone is 2.x, meaning it will happen after SFML 2.2.

But why don't you use the bugfix/al_context branch until then? The more feedback we get, the faster things will progress ;)

@ghost
Copy link

ghost commented Oct 11, 2014

That's what i'm going to do, but I'm still learning a lot in C++ basics, and had some problems using Cmake last time ( almost an afternoon to get SFML2.1 ), so i'm kind of affraid of trying it again !
No choice I guess ;)

EDIT: Downloaded and linked new libraries compiled from: https://github.com/LaurentGomila/SFML/tree/bugfix/al_context
Still have the exact same problem...
Even with only "sf::Sound sound;" in the main function the error still appears.
Only fix I found is using static linking

Some help would be greatly appreciated :)

@eXpl0it3r eXpl0it3r removed this from the 2.x milestone Nov 13, 2014
@fpoisson fpoisson removed this from the 2.x milestone Nov 13, 2014
@eXpl0it3r eXpl0it3r added this to the 2.3 milestone Jan 1, 2015
@zedfax
Copy link

zedfax commented Feb 13, 2016

I've just compiled SFML from master and same problem, my programm exit with value "-1 073 741 515")

@zsbzsb
Copy link
Member

zsbzsb commented Feb 14, 2016

@zedfax Please open a thread on the forum as I kinda doubt this is your issue.

@mihaicirneala
Copy link

I still have the same problem on Windows 10, with dynamic linking and openal32.dll copied in the same dir with the executable..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests