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

Author Topic: When trying to load in music i get an error  (Read 2847 times)

0 Members and 1 Guest are viewing this topic.

svante112

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
When trying to load in music i get an error
« on: August 25, 2013, 08:20:25 pm »
As the title says i get an error when i try to run this

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>

int main()
{
        float spritePosX = 50;
        float spritePosY = 50;

        sf::Music music;
       
        if(!music.openFromFile("music.ogg"))
        {
                return -1;
        }
        music.play();

    sf::RenderWindow window(sf::VideoMode(640, 480), "SFML test");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

        //Fixing texture
        sf::Texture texture;
        if(!texture.loadFromFile("wood.png"))
        {
                return EXIT_FAILURE;
        }
        texture.setSmooth(true);
        texture.setRepeated(false);

        //Fixing sprite
        sf::Sprite sprite;
        sprite.setTexture(texture);
        sprite.setColor(sf::Color::Green);
        sprite.setPosition(sf::Vector2f(spritePosX, spritePosY));

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {

                               
                       

            if (event.type == sf::Event::Closed)
                window.close();

                        if(event.type == sf::Event::KeyPressed)
                        {
                                if(event.key.code == sf::Keyboard::Up)
                                {
                                        sprite.move(0, -5);
                                }
                                if(event.key.code == sf::Keyboard::Down)
                                {
                                        sprite.move(0, 5);
                                }
                                if(event.key.code == sf::Keyboard::Left)
                                {
                                        sprite.move(-5, 0);
                                }
                                if(event.key.code == sf::Keyboard::Right)
                                {
                                        sprite.move(5, 0);
                                }
                                if(event.key.code == sf::Keyboard::R)
                                {
                                        sprite.setColor(sf::Color::Red);
                                }
                                if(event.key.code == sf::Keyboard::G)
                                {
                                        sprite.setColor(sf::Color::Green);
                                }
                                if(event.key.code == sf::Keyboard::B)
                                {
                                        sprite.setColor(sf::Color::Blue);
                                }
                                if(event.key.code == sf::Keyboard::Y)
                                {
                                        sprite.setColor(sf::Color::Yellow);
                                }
                        }

       
                }

                window.clear();
                window.draw(sprite);
        window.display();
    }

    return 0;
}
When i try to run it it says it cant start the program and then (0xc000007b)

When i check output from debug it says

Quote
The program '[8204] SFML 2.1 game.exe' has exited with code -1073741701 (0xc000007b).

I have no clue whats going on  :-[

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: When trying to load in music i get an error
« Reply #1 on: August 25, 2013, 09:03:32 pm »
Tried the code and it's works( instead of *.ogg I had *.ogv). You are sure the problem is from the music/audio?
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
« Last Edit: August 25, 2013, 09:13:51 pm by G. »

svante112

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: When trying to load in music i get an error
« Reply #3 on: August 25, 2013, 09:23:45 pm »
Tried the code and it's works( instead of *.ogg I had *.ogv). You are sure the problem is from the music/audio?

I am sure its the audio becuse if i delete the code it works :/

svante112

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: When trying to load in music i get an error
« Reply #4 on: August 25, 2013, 09:24:53 pm »

svante112

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: When trying to load in music i get an error
« Reply #5 on: August 27, 2013, 05:23:08 pm »
bump

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10845
    • View Profile
    • development blog
    • Email
Re: When trying to load in music i get an error
« Reply #6 on: August 27, 2013, 05:40:32 pm »
The fact that nobody really answered is, that the given information is not enough. As a programmer your most useful tool is the debugger. Run the application through the debugger and find out where it crashes, trace it back and check the states of the classes.

An issue that comes up often is, that you're mixing debug and release modes/libraries.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/