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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - user1

Pages: [1]
1
Graphics / Re: Stuck in event loop when event is triggered
« on: April 08, 2016, 04:58:57 pm »
I'm such a noob. I've removed SFML libraries that I installed from repository and first build and build debug libraries, and now it works fine.

Thanks guys for help

2
Graphics / Re: Stuck in event loop when event is triggered
« on: April 06, 2016, 02:52:43 pm »
You are right, I express myself a wrong way. Program definitely didn't stuck, it's just delay execution.

I will try going through log first, maybe there is some trace of problem. If that doesn't work I'll try debug libraries.

Thanks for advice.

3
Graphics / Re: Stuck in event loop when event is triggered
« on: April 06, 2016, 01:09:37 pm »
Thank you both for taking time to try to help me with this.

Are you implementing key and mouse movement detection?
if you are, how are you doing so?
I didn't implement any key or mouse movement detection. I really can't see way mouse effect my code in any way.

if you are not detecting for keys and mouse movements, and then I can only suggest using the latest release of SMFL.
I'm using SFML v2.3.2.

The more important question is, does that behavior cause any kind of issue for the actual execution of the application?
Program/game is not working or works slowly if there is any input from mouse/keyboard.
Let me give you example. Let's say that I have made pong game and I'm trying to play it on my laptop. If I repeatedly pressed left arrow to move my pedal game will work fine. But if I try to hold left arrow game will run really slow. In case I try to use mouse game will simply stop until I stop moving mouse.

Don't just assume something.
Well, I wouldn't call it assumption.
Here is code to explain what I'm trying to say. This is whole code, I'm not joking

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;

int main() {
    sf::RenderWindow window(sf::VideoMode(640, 490), "SFML works!");    
   
    int frame = 0;
    sf::Clock clock;
    sf::Event event;
    while (window.isOpen()) {
        frame++;
        int eventPerFrame = 0;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            eventPerFrame++;
        }
       
        window.clear();
        window.display();
       
        printf("frame = %d took %.6f sec\n", frame, clock.restart().asSeconds());
    }

    return 0;
}
and this is console output of that code
...
frame 54 took 0.031933 sec
frame 55 took 0.036067 sec
frame 56 took 0.027988 sec <- mouse start moving
frame 57 took 7.220153 sec <- mouse stops moving
frame 58 took 0.051939 sec
frame 59 took 0.032029 sec
frame 60 took 0.027931 sec
frame 61 took 0.039960 sec <- key pressed
frame 62 took 0.664005 sec
frame 63 took 0.180131 sec
frame 64 took 0.303995 sec
frame 65 took 0.060004 sec
...
frame 75 took 0.336035 sec
frame 76 took 0.151967 sec
frame 77 took 0.336002 sec
frame 78 took 0.124075 sec
frame 79 took 0.179965 sec
frame 80 took 0.459949 sec
frame 81 took 0.036032 sec <-- key released
frame 82 took 0.028049 sec
frame 83 took 0.027966 sec
frame 84 took 0.027885 sec
frame 85 took 0.028072 sec
...

Output on my PC looks like this:
... <- mouse start moving
frame = 557 took 0.000590 sec
frame = 558 took 0.018673 sec
frame = 559 took 0.017098 sec
frame = 560 took 0.036095 sec
frame = 561 took 0.020247 sec
frame = 562 took 0.007917 sec
frame = 563 took 0.021471 sec
frame = 564 took 0.028034 sec
frame = 565 took 0.000575 sec
... <- mouse stops moving

It executes on PC much faster even though mouse is moving.

Since it works fine on my PC I installed kernel 3.16 on it to see if that will make this code work same way on my PC as it does on laptop. Well, it still run smoothly on PC.
I will try upgrade my PC to Linux Mint 17.3 (when I find some time) to see if that will "broke" my code. There was changes in Cinnamon since Mint 17 so it might be it. Or something else. Time will show.

4
Graphics / Re: Stuck in event loop when event is triggered
« on: April 06, 2016, 01:40:56 am »
Thanks for reply.

Here's what I did. I edited code like you suggested, but I added one more thing. Before window.isOpen() loop I added int frame = 0. First thing in window.isOpen() loop I increment variable frame. This way I get frame number. On the end of loop I print frame number and number of events in that frame.
...
    int frame = 0;
    while (window.isOpen()) {
        frame++;
...
        int eventPerFrame = 0;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            eventPerFrame++;
        }
...

        window.display();
        cout << frame << " -> " << eventPerFrame << endl;
    }
...
 

Strangest thing is, when mouse is moving console stop printing, and when I stop moving mouse frame number and events per frame are printed again, frame number is incremented by 1 and number of events is 10 – 200 depending how long I was moving mouse.

With keypress is different. In this case frame -> eventsPerFrame pair is sometimes printed, and value is in some cases around 70, sometimes around 120 or 200 although I'm still pressing a key. Frame number is incremented by 1.

In addition I tried this code on my third (and last) computer and same problem has appeared. Program seems stuck in loop when mouse is moving. So here is whole info I gather.

PC
Graphic card: Mobile Radeon HD 1GB
OS: Linux Mint 17 Cinnamon 64-bit
Linux kernel: 3.13
everything works perfect (1-5 events per frame)

Laptop 1 (Acer Aspire v17 Nitro Black Edition)
Graphic card: GeForce GTX 960M 4GB
OS: Linux Mint 17.3 Cinnamon 64-bit
Linux kernel: 4.4
program freezes (up to 300 events per frame)

Laptop 1 (Acer Aspire 5736Z)
Graphic card: Intel Mobile 4 Series Integrated Graphic Controller
OS: Linux Mint 17.2 Cinnamon 64-bit
Linux kernel: 3.16
program freezes (up to 300 events per frame)

What I'm trying to say here is that same code, same project, works on my PC but doesn't works on my laptops (both of them).

5
Graphics / [SOLVED] Stuck in event loop when event is triggered
« on: April 05, 2016, 07:18:55 pm »
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-generic
CPU: 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.

Pages: [1]