First I would like to apologies for my English.
I looked for similar problem in here and on net but couldn't find any so I decide to open new topic.
I have started poking around with SFML and tried to make simple object movement on screen, but from some reason look like execution of my code, when there is some event, get stuck in while window.pollEvent(event) loop, and can't update object position. If there is no event (no mouse movement or key pressed) everything works fine. I attached gif with example what happens.
OS: Linux Mint 17.3 Cinnamon 64-bit
Linux kernel:
4.4.0-13-genericCPU: intel core i7-6700
RAM: 16 GB
Graphic card: GeForce GTX 960M 4GB
SFML: 2.3.2 downloaded from site (didn't tried compiling). Tested on 2.1 from mint repository as well.
IDE: NetBeans 8.1
C++ compiler: g++
Here is my code:
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(640, 490), "SFML works!");
sf::Texture bombTexture;
bombTexture.loadFromFile("data/img/bomb.png");
sf::Sprite bomb;
bomb.setTexture(bombTexture);
sf::Vector2f increment(0.4f, 0.4f);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
if ((bomb.getPosition().x + bombTexture.getSize().x > window.getSize().x && increment.x > 0) ||
(bomb.getPosition().x < 0 && increment.x < 0)) {
increment.x = -increment.x;
}
if ((bomb.getPosition().y + bombTexture.getSize().y > window.getSize().y && increment.y > 0) ||
(bomb.getPosition().y < 0 && increment.y < 0)) {
increment.y = -increment.y;
}
bomb.setPosition(bomb.getPosition() + increment);
window.clear();
window.draw(bomb);
window.display();
}
return 0;
}
To see what happens I changed my code a little bit and did this:
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
...
int i = 0;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
i++;
cout << i << endl;
}
...
it seems that there is triggered 50 - 70 events per sec. And that there is no execution of other code unless event stops (stop moving mouse or release pressed key). Every frame should reset counter (I think), but until event stops console print incremented number. If there is 2-3 sec of mouse movements console will print numbers from 1 to 180 – 200. This shows that program is not exiting loop.
I tried this code on my other computer and for some unknown reason it works fine, object moves no matter what or how many events are triggered.
OS: Linux Mint 17 Cinnamon 64-bit
Linux kernel: 3.13.0-24-generic
CPU: intel core2duo
RAM: 4 GB
Graphic card: Mobile Radeon HD 1GB
SFML: 2.3.2 downloaded from site
IDE: NetBeans 8.0
C++ compiler: g++
Am I doing something wrong or something changed in Linux kernel that affect this? Or is it my hardware?
EDIT:Ok, here is update if anyone is interested. I can't tell what is it, but I can tell what it isn't.
Building SFML from code didn't fix problem.
Upgrade g++ to version 5 didn't fix problem.
Log in with kernel 3.19 didn't fix problem.