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

Author Topic: [SOLVED] Sounds working but exception (ntdll.dll) when closing game  (Read 8046 times)

0 Members and 1 Guest are viewing this topic.

empezar

  • Newbie
  • *
  • Posts: 6
    • View Profile
Hello!

I've searched Google and looked through this forum for solutions to my problem, but to no avail. A few people have had issues with exceptions when quitting, but they don't seem to have the same problem I have.

I'm getting the following exception when quitting:

Code: [Select]
First-chance exception at 0x774F604C (ntdll.dll) in InSpace.exe: 0xC0000005: Access violation reading location 0xFEEEFEF6.
Unhandled exception at 0x774F604C (ntdll.dll) in InSpace.exe: 0xC0000005: Access violation reading location 0xFEEEFEF6.

My call stack looks like this:
Code: [Select]
InSpace.exe!std::_Ref_count_obj<sf::Sound>::_Destroy() Line 944 C++
  InSpace.exe!std::_Ref_count_base::_Decref() Line 118 C++
  InSpace.exe!std::_Ptr_base<sf::Sound>::_Decref() Line 344 C++
  InSpace.exe!std::shared_ptr<sf::Sound>::~shared_ptr<sf::Sound>() Line 611 C++
  InSpace.exe!std::shared_ptr<sf::Sound>::`scalar deleting destructor'(unsigned int) C++
  InSpace.exe!std::allocator<std::shared_ptr<sf::Sound> >::destroy<std::shared_ptr<sf::Sound> >(std::shared_ptr<sf::Sound> * _Ptr) Line 608 C++
  InSpace.exe!std::allocator_traits<std::allocator<std::shared_ptr<sf::Sound> > >::destroy<std::shared_ptr<sf::Sound> >(std::allocator<std::shared_ptr<sf::Sound> > & _Al, std::shared_ptr<sf::Sound> * _Ptr) Line 731 C++
  InSpace.exe!std::_Wrap_alloc<std::allocator<std::shared_ptr<sf::Sound> > >::destroy<std::shared_ptr<sf::Sound> >(std::shared_ptr<sf::Sound> * _Ptr) Line 879 C++
  InSpace.exe!std::_Destroy_range<std::_Wrap_alloc<std::allocator<std::shared_ptr<sf::Sound> > > >(std::shared_ptr<sf::Sound> * _First, std::shared_ptr<sf::Sound> * _Last, std::_Wrap_alloc<std::allocator<std::shared_ptr<sf::Sound> > > & _Al, std::_Nonscalar_ptr_iterator_tag __formal) Line 82 C++
  InSpace.exe!std::_Destroy_range<std::_Wrap_alloc<std::allocator<std::shared_ptr<sf::Sound> > > >(std::shared_ptr<sf::Sound> * _First, std::shared_ptr<sf::Sound> * _Last, std::_Wrap_alloc<std::allocator<std::shared_ptr<sf::Sound> > > & _Al) Line 96 C++
  InSpace.exe!std::vector<std::shared_ptr<sf::Sound>,std::allocator<std::shared_ptr<sf::Sound> > >::_Destroy(std::shared_ptr<sf::Sound> * _First, std::shared_ptr<sf::Sound> * _Last) Line 1567 C++
  InSpace.exe!std::vector<std::shared_ptr<sf::Sound>,std::allocator<std::shared_ptr<sf::Sound> > >::_Tidy() Line 1628 C++
  InSpace.exe!std::vector<std::shared_ptr<sf::Sound>,std::allocator<std::shared_ptr<sf::Sound> > >::~vector<std::shared_ptr<sf::Sound>,std::allocator<std::shared_ptr<sf::Sound> > >() Line 946 C++
  InSpace.exe!Sound::~Sound() Line 7 C++
  [External Code]

I am using SFML version 2.3.1 on Visual Studio 2013.

I am using SFML_STATIC in preprocessor definitions.

I have included the dependencies in the following order:
sfml-audio-s-d.lib
sfml-system-s-d.lib
winmm.lib
openal32.lib
flac.lib
vorbisenc.lib
vorbisfile.lib
vorbis.lib
ogg.lib

I am using the -s versions for the release.

openal32.dll is placed in the project directory.

I should also note that I am only using SFML's sound engine. This is due to the game being a school project where we are supposed to learn the Win32 windows handling stuff (C++).

This is my code: http://paster.se/XECd6

Can you spot any obvious errors?
« Last Edit: August 16, 2015, 02:02:24 pm by empezar »

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Sounds working but exception (ntdll.dll) when closing game
« Reply #1 on: August 16, 2015, 10:59:12 am »
Any chance the sf::SoundBuffer got destroyed before the sf::Sound causing the crash? Although I think that should be prevented already.

Show us some minimal code. :)

empezar

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Sounds working but exception (ntdll.dll) when closing game
« Reply #2 on: August 16, 2015, 11:10:17 am »
Any chance the sf::SoundBuffer got destroyed before the sf::Sound causing the crash? Although I think that should be prevented already.

Show us some minimal code. :)

The code I provided in the link is pretty minimal? :)

These are the important parts I guess:

Code: [Select]
Sound::~Sound()
{
for ( auto &sound : sounds )
sound->stop();
}

std::shared_ptr<sf::Sound> Sound::load(const std::string &filename)
{
auto buffer = std::make_shared<sf::SoundBuffer>();
auto sound = std::make_shared<sf::Sound>();

if ( buffer->loadFromFile(filename) )
sound->setBuffer(*buffer);

buffers.push_back(buffer);
sounds.push_back(sound);

return sound;
}

I've tried destroying the buffers & sounds with the following code but it still throws an exception:

Code: [Select]
Sound::~Sound()
{
for ( auto &sound : sounds )
{
sound->stop();
sound.reset();
}

sounds.clear();
buffers.clear();
}

I might also add that when the exception is thrown, it shows me this code from <memory>:

Code: [Select]
virtual void _Destroy()
{ // destroy managed resource
_Getptr()->~_Ty();
}
« Last Edit: August 16, 2015, 11:15:14 am by empezar »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Sounds working but exception (ntdll.dll) when closing game
« Reply #3 on: August 16, 2015, 11:49:12 am »
If it's an issue with SFML you will be able to recreqte it within a main function. What happens if you just create a sf::Soundbuffer and a sf::Sound instance and play the sound?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

empezar

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Sounds working but exception (ntdll.dll) when closing game
« Reply #4 on: August 16, 2015, 11:54:33 am »
If I put this in main:

Code: [Select]
sf::SoundBuffer buffer;
sf::Sound sound;
if ( buffer.loadFromFile("wind.wav") )
sound.setBuffer(buffer);
sound.play();

It works.

I guess I'll have to rethink my Sound class or just not use it.

Thanks a lot!
« Last Edit: August 16, 2015, 12:20:44 pm by empezar »

empezar

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Sounds working but exception (ntdll.dll) when closing game
« Reply #5 on: August 16, 2015, 12:21:29 pm »
Hmmm. This presents a whole new problem with the buffer running out of scope when I create new buffers everywhere. So it's not really a solution for me, yet. All the tutorials around also only use the main function. Getting a sound to play there is simple.

Again, I tried declaring the sound buffer as a shared pointer to use in other classes:

Code: [Select]
std::shared_ptr<sf::SoundBuffer> soundBuffer;
And again, I get the same exception as before.

EDIT: I solved this problem by issuing the following after the game loop finishes:

Code: [Select]
soundBuffer.reset();
« Last Edit: August 16, 2015, 12:25:33 pm by empezar »

empezar

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Sounds working but exception (ntdll.dll) when closing game
« Reply #6 on: August 16, 2015, 12:35:56 pm »
And now I finally solved the issue using my original code.

I was lacking a destructor for my Game class (which initialized the Sound class).

Code: [Select]
Game::~Game()
{
sound.reset();
}

With this, I could completely remove the Sound destructor.

Thank you for pointing me in the right direction :)