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

Author Topic: sf::Window::GetFrameTime() returns 0  (Read 2094 times)

0 Members and 1 Guest are viewing this topic.

Sutur

  • Newbie
  • *
  • Posts: 5
    • View Profile
sf::Window::GetFrameTime() returns 0
« on: April 21, 2011, 10:35:51 pm »
Hello folks!

Everytime I call sf::Window::GetFrameTime() it returns 0 which can't be true.
It was working a few days ago and I did not update/change any of the SFML files.
Even if I put sf::Sleep( 0.5 ) inside my applications main loop, it still returns 0.
Any idea how this could be caused?

I'm using Linux 64bit ( Ubuntu ) together with g++ and SFML 2.0.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Window::GetFrameTime() returns 0
« Reply #1 on: April 21, 2011, 11:03:48 pm »
Can you show your code?
Laurent Gomila - SFML developer

Sutur

  • Newbie
  • *
  • Posts: 5
    • View Profile
sf::Window::GetFrameTime() returns 0
« Reply #2 on: April 21, 2011, 11:21:04 pm »
This prints 0 over and over again:

Code: [Select]
#include <SFML/Window.hpp>
#include <iostream>

int main()
{
sf::Window window( sf::VideoMode( 800, 600 ), "" );

while( window.IsOpened() )
{
sf::Event event;
while( window.GetEvent( event ) )
if( event.Type == sf::Event::KeyPressed || event.Type == sf::Event::Closed )
window.Close();

sf::Sleep( 0.5 );
window.Display();

std::cout << window.GetFrameTime() << std::endl;
}
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Window::GetFrameTime() returns 0
« Reply #3 on: April 22, 2011, 09:06:24 am »
That's really weird. What if you directly use a sf::Clock instead?
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
sf::Window::GetFrameTime() returns 0
« Reply #4 on: April 22, 2011, 11:22:47 am »
Isn't it the correct behaviour if you call Display right before GetFrameTime ?
SFML / OS X developer

Revan1985

  • Newbie
  • *
  • Posts: 4
    • MSN Messenger - davide_galli_420@hotmail.it
    • View Profile
sf::Window::GetFrameTime() returns 0
« Reply #5 on: April 22, 2011, 11:32:25 am »
i've always noticed that the GetFrameTime works only (on my pc), if i call it before the draw

Code: [Select]

sf::Sleep( 0.5);
std::cout << window.GetFrameTime() << std::endl;
window.Display();
     


this should work...
Best Regards
    Davide Galli

* - junior c# programmer
* - base c++/opengl programmer
* - near having a motorbike.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Window::GetFrameTime() returns 0
« Reply #6 on: April 22, 2011, 12:04:05 pm »
GetFrameTime() can be called at any time, it returns the time from the last frame, not the current one. So the result doesn't depend on the moment when you call it.
Laurent Gomila - SFML developer

Sutur

  • Newbie
  • *
  • Posts: 5
    • View Profile
sf::Window::GetFrameTime() returns 0
« Reply #7 on: April 22, 2011, 06:46:39 pm »
Code: [Select]

      std::cout << window.GetFrameTime() << std::endl;
      window.Display();


It keeps telling me 0.
So does the following code:

Code: [Select]

#include <SFML/Window.hpp>
#include <iostream>

int main()
{
   sf::Window window( sf::VideoMode( 800, 600 ), "" );
   sf::Clock frameTimeCounter;

   while( window.IsOpened() )
   {
      frameTimeCounter.Reset();

      sf::Event event;
      while( window.GetEvent( event ) )
         if( event.Type == sf::Event::KeyPressed || event.Type == sf::Event::Closed )
               window.Close();

      sf::Sleep( 0.5 );
      window.Display();
     
      std::cout << frameTimeCounter.GetElapsedTime() << std::endl;
   }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Window::GetFrameTime() returns 0
« Reply #8 on: April 22, 2011, 07:25:17 pm »
Try to replace Sleep(0.5) with an active loop that takes some time.
Laurent Gomila - SFML developer

Sutur

  • Newbie
  • *
  • Posts: 5
    • View Profile
sf::Window::GetFrameTime() returns 0
« Reply #9 on: April 24, 2011, 02:38:57 pm »
Quote from: "Laurent"
Try to replace Sleep(0.5) with an active loop that takes some time.

Does not change the behavior at all.

However, I managed to get it working by turning off Compiz.
Now the correct values are returned.
But I would really like it to work together with Compiz.
Please tell me if you can think of any solution.

Thanks in advance!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Window::GetFrameTime() returns 0
« Reply #10 on: April 24, 2011, 06:29:26 pm »
Quote
Does not change the behavior at all.

So your program runs actively for a significant amount of time, and the clock still returns 0 second elapsed??

Quote
However, I managed to get it working by turning off Compiz.

Compiz usually conflicts with OpenGL stuff, I don't know how it can mess up time measurement.
SFML simply uses the gettimeofday function to measure time, there's nothing weird behind the sf::Clock class.
Laurent Gomila - SFML developer

Sutur

  • Newbie
  • *
  • Posts: 5
    • View Profile
sf::Window::GetFrameTime() returns 0
« Reply #11 on: April 27, 2011, 10:01:14 pm »
Quote from: "Laurent"

So your program runs actively for a significant amount of time, and the clock still returns 0 second elapsed??

Yes, it did.
I switched to the latest SFML2 version( the one I was using before had been a few months old ) and it seems like it's now doing the job. I propably somehow messed up my previous SFML2 download.

Thanks for your help!