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

Author Topic: Huge problem with SFML  (Read 7677 times)

0 Members and 1 Guest are viewing this topic.

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Huge problem with SFML
« on: January 06, 2010, 08:50:57 pm »
This is a total game breaker for me unless I am missing something huge here.

The problem is when I add GetEvent(Event) in my code it slows or even STOPS my program when I move the mouse around.

I display the fps and even added a counter to increment each time the program loops and they both stop dead when I move the mouse.

I have been puzzling over this for quite a while and I cannot find anything on the forum about it.

Here is my code, someone else please run it and see if you get the same results:

Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
    sf::Font MyFont;
    sf::String fps;
    sf::String counter;
    char buffer[200];
    int num = 0;

    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");

    if (!MyFont.LoadFromFile("font/small/XPAIDERP.TTF", 8))
        return EXIT_FAILURE;

    fps.SetFont(MyFont);
    fps.SetSize(8);
    fps.SetPosition(100.f, 100.f);

    counter.SetFont(MyFont);
    counter.SetSize(8);
    counter.SetPosition(100.f, 200.f);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        App.Clear();

        sprintf( buffer, "FPS = %f", 100.f / App.GetFrameTime() );
        fps.SetText( buffer );
        App.Draw( fps );

        sprintf( buffer, "COUNTER = %d", num );
        counter.SetText( buffer );
        App.Draw( counter );

        App.Display();

        num++;
    }

    return EXIT_SUCCESS;
}


I move the mouse around and both the counter and the fps freeze. This can only mean the program itself is freezing. If I comment out while (App.GetEvent(Event)) then everything goes smoothly and I can move the mouse around with no freezing.

System:

WindowsXP service pack 3
DirectX 9.0c
AMD athlon 2.21 GHZ
2 GB RAM

Using Code::blocks IDE with MingW

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Huge problem with SFML
« Reply #1 on: January 06, 2010, 09:22:56 pm »
Your program ran fine for me (after commenting out the font stuff).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Huge problem with SFML
« Reply #2 on: January 06, 2010, 09:23:22 pm »
Maybe you receive a huge amount of unexpected events. Can you add some logs in your event loop to know what is received exactly?
Laurent Gomila - SFML developer

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Huge problem with SFML
« Reply #3 on: January 07, 2010, 12:56:31 am »
Quote from: "Laurent"
Maybe you receive a huge amount of unexpected events. Can you add some logs in your event loop to know what is received exactly?


Ok here is what I did. I added a counter to the event loop to increment each time there is an event. Then I displayed the counter on screen to see how many times the event loop was running.

The result was that the event looped maybe 3 times when I moved the mouse cursor a small distance. However this was still freezing both the fps and the main program loop counter. So for some reason App.GetEvent(Event) is running hella slow on my system.

Here is the new code:

Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
    sf::Font MyFont;
    sf::String fps;
    sf::String counter;
    sf::String EventCount;
    char buffer[200];
    int num = 0;
    int evnum = 0;

    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Window");

    if (!MyFont.LoadFromFile("font/small/XPAIDERP.TTF", 8))
        return EXIT_FAILURE;

    fps.SetFont(MyFont);
    fps.SetSize(8);
    fps.SetPosition(100.f, 100.f);

    counter.SetFont(MyFont);
    counter.SetSize(8);
    counter.SetPosition(100.f, 200.f);

    EventCount.SetFont(MyFont);
    EventCount.SetSize(8);
    EventCount.SetPosition(100.f, 300.f);

    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if( Event.Type == sf::Event::Closed )
                App.Close();

            evnum++;
        }

        App.Clear();

        sprintf( buffer, "FPS = %f", 100.f / App.GetFrameTime() );
        fps.SetText( buffer );
        App.Draw( fps );

        sprintf( buffer, "COUNTER = %d", num );
        counter.SetText( buffer );
        App.Draw( counter );

        sprintf( buffer, "EVENTS = %d", evnum );
        EventCount.SetText( buffer );
        App.Draw( EventCount );

        App.Display();

        num++;
    }

    return EXIT_SUCCESS;
}


I am using sfml version 1.5

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Huge problem with SFML
« Reply #4 on: January 07, 2010, 09:03:01 am »
Did you try the samples provided in the SFML SDK?
Laurent Gomila - SFML developer

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Huge problem with SFML
« Reply #5 on: January 07, 2010, 12:22:32 pm »
Quote from: "Laurent"
Did you try the samples provided in the SFML SDK?


Yep, just ran pong and same problem. When I move the mouse the ball freezes.

Same thing with opengl, the rotating cube freezes.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Huge problem with SFML
« Reply #6 on: January 07, 2010, 12:59:45 pm »
What happens when you stop moving the mouse? Does the program run smoothly again, or does it stay frozen?
Laurent Gomila - SFML developer

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Huge problem with SFML
« Reply #7 on: January 07, 2010, 04:09:12 pm »
Quote from: "Laurent"
What happens when you stop moving the mouse? Does the program run smoothly again, or does it stay frozen?


It starts running smoothly again.

The mouse movement makes the most visible effect, but it also gets choppy when I hold down a key on the keyboard.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Huge problem with SFML
« Reply #8 on: January 07, 2010, 04:58:07 pm »
How many events do you have when you press a single key?
Laurent Gomila - SFML developer

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Huge problem with SFML
« Reply #9 on: January 07, 2010, 06:06:02 pm »
Quote from: "Laurent"
How many events do you have when you press a single key?


I go through the event loop twice. Looks like one for the press and one for the release.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Huge problem with SFML
« Reply #10 on: January 07, 2010, 07:02:45 pm »
Yes, it looks ok :?
Laurent Gomila - SFML developer

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Huge problem with SFML
« Reply #11 on: January 08, 2010, 04:18:33 am »
use a log file or something other than sf::strings to see if it has something to do with that.
Eugene Alfonso
GTP | Twitter

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Huge problem with SFML
« Reply #12 on: January 08, 2010, 05:08:21 am »
Quote from: "phear-"
use a log file or something other than sf::strings to see if it has something to do with that.


It has nothing to do with sf::strings.

If I comment out the event loop everything runs smoothly.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Huge problem with SFML
« Reply #13 on: January 08, 2010, 07:45:32 am »
Have you tried switching between static and dynamic libraries? Debug and release?
Laurent Gomila - SFML developer

chris67

  • Newbie
  • *
  • Posts: 12
    • View Profile
Huge problem with SFML
« Reply #14 on: January 08, 2010, 07:04:54 pm »
I ran it again and everything is running smoothly now. I have no idea why :?

Yesterday I installed Visual C++ 2008 express. Then I uninstalled microsoft presentation foundation, which I think came with VC++ 2008 express.

Those are the only things I remember doing between the time it wasn't working and now.

Very strange.

 

anything