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

Author Topic: Error 0xc0000005 when trying to load wav file  (Read 2060 times)

0 Members and 1 Guest are viewing this topic.

chprieto

  • Newbie
  • *
  • Posts: 3
    • View Profile
Error 0xc0000005 when trying to load wav file
« on: March 07, 2025, 06:28:59 am »
Hi! I'm new to SFML and have been trying to load and play a wav file. When trying to run my program I get the error C:\Users\Chpri\source\repos\Piano Test\x64\Debug\Piano Test.exe (process 31640) exited with code -1073741819 (0xc0000005), without the sound playing.

The code in question is a very simple test program.
#include <SFML/audio.hpp>

 int main() {
     
     sf::SoundBuffer buffer;
     if (!buffer.loadFromFile("a1.wav"))
         return -1;

     sf::Sound sound(buffer);
     sound.play();
   
     return 0;
 }
 

I'm using Visual Studio and have tried moving the wav file to everywhere I can think of (the main directory with the .sln file, the folder with the executable, as a file in the solution explorer), nothing seems to effect the error.

Is the error due to where the file goes, or is there some other problem?

Thanks!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11175
    • View Profile
    • development blog
    • Email
Re: Error 0xc0000005 when trying to load wav file
« Reply #1 on: March 07, 2025, 08:08:49 am »
0xc0000005 usually means you're using the wrong DLL, e.g. using x86 instead of x64

If this is using SFML 2, you might have copied the wrong OpenAL32.dll or not copied any and it's finding one in PATH.
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

chprieto

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Error 0xc0000005 when trying to load wav file
« Reply #2 on: March 07, 2025, 04:36:10 pm »
I'm using SFML 3 and copied all the dll files from the bin folder in my SFML installation, which I'm almost certain is the 64-bit version. Is there any way to make sure that they are correct?

If it matters, I was able to run the test code that was in this tutorial

https://www.sfml-dev.org/tutorials/3.0/getting-started/visual-studio/#creating-and-configuring-an-sfml-project

its only when I'm trying to load the wav file that the error happens.

chprieto

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Error 0xc0000005 when trying to load wav file
« Reply #3 on: March 07, 2025, 04:51:25 pm »
Never mind, I got it to work. It looks like when running in Visual Studio I had to link to the debug libraries, regardless of whether I was using the debugger or not.

Thanks for the help!

kojack

  • Sr. Member
  • ****
  • Posts: 364
  • C++/C# game dev teacher.
    • View Profile
Re: Error 0xc0000005 when trying to load wav file
« Reply #4 on: March 08, 2025, 12:54:29 am »
In Visual Studio STL classes have different sizes depending on release or debug build type. For example std::filesystem::path is 32 bytes in release but 40 bytes in debug (extra debug info added). This also happens for strings and other std classes.

So if your program calls a function in a library of the wrong type and the parameters to the function are STL classes (such as SFML's SoundBuffer::loadFromFile taking an std::filesystem::path), then the function's code will see corrupt data.

 

anything