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

Author Topic: Trouble with openFromfile  (Read 3860 times)

0 Members and 1 Guest are viewing this topic.

SplashFreeze

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Trouble with openFromfile
« on: September 24, 2018, 05:05:01 am »
I don't understand why I keep getting the error message
The code is built successfully but when I try to debug it in Visual Studio, I get this error message:

the procedure entry point ?play@SoundStream@sf@UAEXXZ could not be located in the Dynamic Link Library

I added all the dll's from the sfml bin to the executable to no avail.

This is the code.


// Anything after // is a comment not actual C++ code
// Comments are important and I use them to explain things
// Why not read the comments in this code

// These "include" code from the C++ library and SFML too

#include <SFML/Graphics.hpp>
#include <SFML/Audio/Music.hpp>
// This is the main C++ program- Duh!
// It is where our game starts from
int main()
{
        sf::Music bgmusic;
        bgmusic.openFromFile("RockGuitar.wav");
        // Make a window that is 800 by 200 pixels
        // And has the title "Hello from SFML"
        sf::RenderWindow window(sf::VideoMode(800, 200), "Hello from SFML");

        // Create a "Text" object called "message". Weird but we will learn about objects soon
        sf::Text message;

        // We need to choose a font
        sf::Font font;
        font.loadFromFile("28 Days Later.ttf");

        // Set the font to our message
        message.setFont(font);

        // Assign the actual message
        message.setString("I want to pill myself");

        // Make it really big
        message.setCharacterSize(100);

        // Choose a color
        message.setFillColor(sf::Color::White);

        // This "while" loop goes round and round- perhaps forever
        while (window.isOpen())
        {
                // The next 6 lines of code detect if the window is closed
                // And then shuts down the program
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                // Someone closed the window- bye
                                window.close();
                }

                // Clear everything from the last run of the while loop
                window.clear();

                // Draw our message
                window.draw(message);

                // Draw our game scene here
                // Just a message for now

                // Show everything we just drew
                window.display();
                bgmusic.play();
        }// This is the end of the "while" loop

        return 0;
}


Can anyone help??
« Last Edit: October 04, 2018, 02:57:20 pm by Laurent »

Antonio9227

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Trouble with openFromfile
« Reply #1 on: October 04, 2018, 01:10:06 pm »
One thing that I noticed right away is that you call the play method each frame. It's enough to call it once before the game loop and the music will continue playing.

I also recommend using window.setFramerateLimit(60); because right now your program will try to run as fast as possible, getting you hundreds of FPS but also consuming all of the available processing power.

Code: [Select]
sf::Music mymusic;
mymusic.openFromFile("somefile.ogg");
mymusic.play();

window.setFramerateLimit(60);

while(window.isOpen())
{
    //draw and update stuff
}

Otherwise make sure your environment is set up properly and you copied over the necessary dll files (in the same folder as your exe). I got similar problems in the past by improperly setting up Visual Studio and I kept getting similar errors
« Last Edit: October 04, 2018, 01:11:37 pm by Antonio9227 »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Trouble with openFromfile
« Reply #2 on: October 05, 2018, 03:39:41 pm »
Make sure that you are using debug libraries (with -d) with debug build and release libraries (without -d) with release build.
Make sure that the libraries are built with the exact version of compiler that you are using.
Make sure that the DLLs (you are not linking statically, I presume) are the same version as the headers that you have linked.

They are all common mistakes especially the third one, which is when you update SFML but forget to update the DLLs from the new version.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything