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

Author Topic: Crashing When Program Closes with sf::Music  (Read 11138 times)

0 Members and 1 Guest are viewing this topic.

Tofugames

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Crashing When Program Closes with sf::Music
« on: April 29, 2012, 11:36:17 pm »
Hello, I am working on trying to get Music working in my project, and have run into a strange issue where regardless of what I do with an sf:Music object, even if I simply only have one declared at all and regardless of where in my program it is declared, the program crashes or breaks when main() returns. I am using the SFML 2.0 RC on Windows XP Service Pack 3, if that makes any difference.

Other sounds play and work perfectly fine and the music plays fine if I have code in to load and play it, however regardless of whether that code is in or not it still crashes on exit.

Edit: I have tested the program on a computer running Windows 7 with the same Dlls and SFML version, and the error is not reproduced on it, so this seems to be an issue that is exclusive to Windows XP Service Pack 3, or at least for me.

Here is some code to show the issue:

Code: [Select]
#include <SFML/Audio.hpp>
 
int main()
{
sf::Music test;

        //It crashes with or without the following sf::Music related lines
        test.openFromFile("test.ogg");
        test.play();
        test.stop();

        //It also crashes with the same error with or without a main game loop
        //and window, so I removed the main game loop and render window code
        //from this snippet.
       
        return 0;
}

This is what comes up in the output box in VC++ when it crashes on exit:

Quote
First-chance exception at 0x004653cc in SFML Basic Build.exe: 0xC0000005: Access violation reading location 0x00a3c820.
Unhandled exception at 0x004653cc in SFML Basic Build.exe: 0xC0000005: Access violation reading location 0x00a3c820.

Any help on this would be greatly appreciated,

Thanks!

Here is a screenshot of the program crashing on exit when built as a release build and run from the exe:




~~Tofugames
« Last Edit: April 30, 2012, 02:51:42 am by Tofugames »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Crashing When Program Closes with sf::Music
« Reply #1 on: April 30, 2012, 12:08:21 am »
Make sure your application loads the DLLs supplied with SFML (libsndfile and OpenAL). And also the right SFML DLLs (compiler version, debug/release).

Otherwise, try to come up with a complete and minimal example that reproduces the problem.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tofugames

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #2 on: April 30, 2012, 12:27:27 am »
I updated my post to be more clear and direct to the problem. I also did make sure that it is using the correct DLLs and is loading them as well. I tested my program with the exact same DLLs and SFML version on another computer that is running Windows 7, and did not have the error on that computer, so I think the problem is exclusive to Windows XP (Service Pack 3), for me at least.

God_Man

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Crashing When Program Closes with sf::Music
« Reply #3 on: May 09, 2012, 11:18:05 pm »
Same thing happens to me,I did not have this issue with 1.6.I removed the audio portion from my app and the error goes away whenever I close the app.

I debugged the app and it ran into an issue with loading an ogg file,thats what lead me to the audio portion causing an error.


I like 1.6 more,I only updated to use thor for animation reasons,I thor gives me an error.Compiles fine,but when I run my app I get "The procedure entry point ?Load FromFile SoundBuffer@sf@@QAE_NABV?basic_string yadda yadda yadda"

Again another audio issue.

Wish thor worked for 1.6 :/

Tenrag

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #4 on: March 14, 2013, 06:18:08 pm »
Sorry for reviving an old topic but I just installed SFML 2.0 RC and
got exact the same problem for which I found solution.

I was getting error after just declaring sf::Music object like this:
#include <SFML/Audio.hpp>
int main()
{
    sf::Music m;
    return 0;
}
All I had to do was to add brackets:
#include <SFML/Audio.hpp>
int main()
{
    sf::Music m();
    return 0;
}
and it worked, no more access volation.

I guess it has to be something with  sf::Music destructor trying to free memory that was never allocated because error occurred always in the end of the program and object could be used normally without any problems until that moment.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #5 on: March 14, 2013, 06:24:15 pm »
I'd claim that you changed something else in between adding the brackets, because semantically it's the exact same thing. Both call the default constructor of sf::Music and it doesn't matter if you use the brackets or not.
Does it still crash if you'd now remove the brackets?

Besides it's a known and not yet fixed issue, see #30. ;)

And you might want to update to the latest version directly from GitHub. The RC is already quite old and in the meantime we've seen many improvements.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tenrag

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #6 on: March 14, 2013, 06:34:41 pm »
I know it's the same thing but I checked multiple times by adding brackets, rebuilding ,running , removing brackets, rebuilding...
I assure you I didn't do anything in between.

I don't know why, but it's happening before my eyes.
But since it was reported then never mind.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #7 on: March 14, 2013, 06:40:09 pm »
I know it's the same thing but I checked multiple times by adding brackets, rebuilding ,running , removing brackets, rebuilding...
I assure you I didn't do anything in between.
Hmm okay, that's odd. ;D

What compiler did you use, which mode (debug, release?) and how did you link against SFML (dynamic, static?)?

If you know your way around your tools, you could make a diff between the two versions in ASM, to see what changes.
Personally I guess the compiler simply (for some reason) reorders the destruction order of the Device etc. and thus at one point it leads to a crash and at another point it doesn't.
Also if you haven't tested it, you should see how debug vs release acts. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Tenrag

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #8 on: March 14, 2013, 06:56:46 pm »
I use compiler that comes with Visual Studio 2010 and dynamic linking

I tried release mode and there is no problem there, it runs without brackets.



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #9 on: March 14, 2013, 07:02:03 pm »
It's not the same thing at all, the second one is a function declaration, no variable is created.
Laurent Gomila - SFML developer

SwatzZ

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #10 on: May 13, 2013, 06:25:32 pm »
I've got the same problem. When closing the program, it opens a window which is saying:

Quote
First-chance exception at 0x005353cc in program.exe: 0xC0000005: Access violation reading location 0x01f5e6b0.

At the same time there's a code called free.c opening next to the main.cpp. There's a green arrow pointing at:
retval = HeapFree(_crtheap, 0, pBlock);
        if (retval == 0)
        {
            errno = _get_errno_from_oserr(GetLastError());
        }

I tried to reinstall sfml 2.0, but it didn't change. It works perfectly without sf::sound.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #11 on: May 13, 2013, 06:33:06 pm »
Read answer #5 above ;)
Laurent Gomila - SFML developer

SwatzZ

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #12 on: May 13, 2013, 07:13:50 pm »
I did, but it isn't working though  :-\
My Code:
        sf::Music backgroundmusic();
        backgroundmusic().openFromFile("Music and Sound/Pokemon_Theme.ogg");
        backgroundmusic().setVolume(50);
        backgroundmusic().setLoop(true);
        backgroundmusic().play();

It's saing something about unresolved externals.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #13 on: May 13, 2013, 10:45:03 pm »
Of course it's not working. The relevant answer says:

Quote
it's a known and not yet fixed issue, see #30

Quote
It's saing something about unresolved externals.
What? Are we talking about a crash or something else?
Your code produces errors because you declare a function, not an instance. This is also what is explained above.
Laurent Gomila - SFML developer

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: Crashing When Program Closes with sf::Music
« Reply #14 on: May 15, 2013, 11:03:24 pm »
I did, but it isn't working though  :-\
My Code:
        sf::Music backgroundmusic();
        backgroundmusic().openFromFile("Music and Sound/Pokemon_Theme.ogg");
        backgroundmusic().setVolume(50);
        backgroundmusic().setLoop(true);
        backgroundmusic().play();

It's saing something about unresolved externals.

sf::Music backgroundmusic();
is a function declaration that takes nothing as its argument and returns sf::Music object.
Correct way to declare a sf::Music object is
sf::Music backgroundmusic;