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

Author Topic: [BUG?] RenderWindow's setVerticalSyncEnabled resets when .create() is called  (Read 2049 times)

0 Members and 1 Guest are viewing this topic.

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Making an options menu I realized .setVerticalSyncEnabled() resets when .create() is called.
I think this may be a bug, because for example setFramerateLimit doesnt reset at all
Below I provide small examples to show what I mean.

this is the code to show setFramerateLimit  doesn't reset (to "unlimited" FPS)  when create() is called
#include <SFML/Graphics.hpp>
#include <sstream>

using namespace sf;
using namespace std;

int main()
{
    RenderWindow app(VideoMode(800, 600, 32), "SFML Test");
    app.setFramerateLimit(60);
    app.create(VideoMode(800, 600, 32), "SFML Test");
    Clock myClock;
    float fps = 1 / myClock.restart().asSeconds();
    stringstream ssFPS;
    ssFPS << "fps: " << fps;
    Text myText(ssFPS.str());

    while (app.isOpen()){
        Event evento;
        while (app.pollEvent(evento)){
            if (evento.type == Event::Closed){
                app.close();
            }
        }

        fps = 1 / myClock.restart().asSeconds();
        stringstream ssFPS;
        ssFPS << "fps: " << fps;
        Text myText(ssFPS.str());

        app.clear();
        app.draw(myText);
        app.display();
    }

    return 0;
}
 

This is the code to show that setVerticalSyncEnabled does reset to false if create() is called

#include <SFML/Graphics.hpp>
#include <sstream>

using namespace sf;
using namespace std;

int main()
{
    RenderWindow app(VideoMode(800, 600, 32), "SFML Test");
    app.setVerticalSyncEnabled(true);
    app.create(VideoMode(800, 600, 32), "SFML Test");
    Clock myClock;
    float fps = 1 / myClock.restart().asSeconds();
    stringstream ssFPS;
    ssFPS << "fps: " << fps;
    Text myText(ssFPS.str());

    while (app.isOpen()){
        Event evento;
        while (app.pollEvent(evento)){
            if (evento.type == Event::Closed){
                app.close();
            }
        }

        fps = 1 / myClock.restart().asSeconds();
        stringstream ssFPS;
        ssFPS << "fps: " << fps;
        Text myText(ssFPS.str());

        app.clear();
        app.draw(myText);
        app.display();
    }

    return 0;
}
 

a simple fix is to set setVerticalSyncEnabled to true, every time you call .create(), like this:
//code here
    app.create(VideoMode(800, 600, 32), "SFML Test");
    app.setVerticalSyncEnabled(true);
//rest of the code
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Can you please add it to the task tracker so that it doesn't get forgotten? Thanks :)
Laurent Gomila - SFML developer

santiaboy

  • Full Member
  • ***
  • Posts: 118
    • View Profile
I'm guessing this is the task tracker (https://github.com/SFML/SFML/issues?state=open)
Here's the issue link (I didn't know how to label it as bug, window) https://github.com/SFML/SFML/issues/371

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Thanks :)

Labels can only be assigned by admins.
Laurent Gomila - SFML developer