I have written a simple example. However it does not reproduce the issue.
However I realized that the very first call is done from a non-main thread, when the app is reading preferences and other stuff. I guess this might cause the issue?
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>
#include <iostream>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
window.setVerticalSyncEnabled(true); // Troubles if this is called from a background thread
std::cout << "VSync now enabled\n";
sf::Clock clock;
int step = 0;
int frames = 0;
const int FRAMES = 120;
auto restartClockAndDumpTime = [&clock, &step, &frames]
{
std::cout << "Step " << step << ", FPS : "
<< (FRAMES / clock.restart().asSeconds()) << "\n";
frames = 0;
};
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color(0xcccc00));
window.display();
if (++frames < FRAMES)
{
continue;
}
switch (step)
{
case 0:
++step;
break;
case 1:
restartClockAndDumpTime();
window.setVerticalSyncEnabled(false);
std::cout << "VSync now disabled\n";
++step;
break;
case 2:
restartClockAndDumpTime();
window.setVerticalSyncEnabled(true);
std::cout << "VSync now enabled\n";
++step;
break;
case 3:
restartClockAndDumpTime();
++step;
break;
case 4:
return 0;
}
}
}