I'm using Visual Studio 2010 with default compiler and all that.
Edit: Also, I'm using dynamic SFML2 binaries I compiled myself. Both a version pulled a bit over a month ago and a recent one I built yesterday do not work.
I noticed that a game I'm working on functioned differently when built in the default Release configuration than in the Debug configuration. It's an early prototype, it only has a sprite moving left and right on the screen from keyboard input, but in Release mode it didn't move at all. After some examination I noticed I could still press Esc to close the SFML window, so not all input was disfunctional.
Edit: So Esc worked, but WASD for movement didn't. I figured I would compare if a same action executed by different keys would work, comparing Esc and WASD. I tried the following minimal code (posted and reported as working by
eXpl0it3r).
#include <SFML/Graphics.hpp>
int main ()
{
sf::RenderWindow window(sf::VideoMode(1024, 768), "Test");
window.setFramerateLimit(20);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
window.close();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
{
window.close();
}
window.clear();
window.display();
}
return 0;
}
For me, this piece of code does not work in Release mode. Esc closes the window if I press it first. D doesn't close the window. If I first press D, and after that press Esc, the Esc doesn't close the window anymore. And I am linking to correct binaries, using release files in release mode as I should.
I switched from using sf::Keyboard::isKeyPressed() to polling events from the SFML window and catching KeyPressed and KeyReleased events. This works as expected and my project now functions as it should.
Does anyone have some idea so far, with the information provided, what could be causing this behaviour? What could be causing my code to behave so differently in Release and Debug configurations, that's what I'm primarily worried about as I might have just hidden the problem instead of really solving it.