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

Author Topic: Image is not displayed and application uses 100% CPU  (Read 1175 times)

0 Members and 1 Guest are viewing this topic.

Ethon

  • Newbie
  • *
  • Posts: 4
    • View Profile
Image is not displayed and application uses 100% CPU
« on: January 25, 2013, 01:22:27 pm »
Hey,
since a few days my SFML application stopped working. So I tried a basic setup and it also doesn't work.

#include <SFML/System/Sleep.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    // Create the main window
    sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

    sf::Texture texture;
    if(!texture.loadFromFile("Data/Image/Background.png"))
        return EXIT_FAILURE;
    sf::Sprite bg(texture);

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                return 0;
            }
        }

        window.draw(bg);
        // sf::sleep(sf::milliseconds(5));
    }
}

SFML: The latest SFML-2.0-rc from the download page. I also tried to source distribution which I compiled myself.
OS: Linux, Fedora 17

Problem: The sprite is not displayed (The window contains that what previously was at the position on the screen),
CPU usage goes up to maximum and there is a huge latency when trying to close the windows. (Up to a few minutes, therefor the sleep).

Any advice? Thanks. :)
Regards,
Ethon

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Image is not displayed and application uses 100% CPU
« Reply #1 on: January 25, 2013, 01:43:30 pm »
Look at the sf::RenderWindow doc.
You need to call window.display() in order to display anything that has been drawn.
If you don't want to use 100% CPU set a fps limitation with setFramerateLimit or enable the vertical synchronization with setVerticalSyncEnabled.

Ethon

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Image is not displayed and application uses 100% CPU
« Reply #2 on: January 25, 2013, 01:47:43 pm »
What the hell ... I feel so stupid now.
I guess I accidently removed that line of code from my project.

Thanks for pointing that out, a shame I didn't notice myself.