SFML community forums

Help => Window => Topic started by: drobole on December 30, 2009, 02:17:02 am

Title: GetEvent always returns true
Post by: drobole on December 30, 2009, 02:17:02 am
Hi again,

I seem to have a problem with events when I migrate my code to linux and gcc

Here is a snippet of my game loop:

Code: [Select]

void StateManager::startRendering()
{
mRunning = true;
while (mRunning)
{
while (mRenderWindow->GetEvent(mEvent))
{
if (mEvent.Type == Event::Closed)
{
mRunning = false;
}
else if(mEvent.Type == Event::KeyPressed)
{
mStates.back()->keyPressed((Event::KeyEvent&)mEvent.Key);
}
else if(mEvent.Type == Event::KeyReleased)
{
mStates.back()->keyReleased((Event::KeyEvent&)mEvent.Key);
}
}

mRenderWindow->Clear();

if(mStates.back()->frameRender(*mRenderWindow))
{
                 mRunning = false;
}

mRenderWindow->Display();
}

mRenderWindow->Close();
}


This code works fine on windows and VC++, but in linux the event while loop --> while (mRenderWindow->GetEvent(mEvent)) <-- always returns true.
According to the debugger the first few events catched seems reasonable (Joy_Moved, Gained_Focus and Mouse_Entered)
After that it constantly receives the event Mouse_Moved.
The while loop never stops and obviously the code never reaches the actual rendering futher down.
I have tried to replace the while with an if, and then things start to work as expected. But I don't want to do that do I?

Am I overlooking something here or is this a bug?
Title: GetEvent always returns true
Post by: Laurent on December 30, 2009, 10:49:43 am
Hi

Can you show a minimal and complete piece of code that reproduces this problem?
Title: GetEvent always returns true
Post by: drobole on December 30, 2009, 10:17:52 pm
Quote from: "Laurent"
Hi

Can you show a minimal and complete piece of code that reproduces this problem?


Code: [Select]

#include <string.h>
#include <SFML/Window.hpp>
using namespace sf;

int main()
{
    Window App(sf::VideoMode(800, 600, 32), "SFML Window");
    App.ShowMouseCursor(false); // this one doesn't help

    bool Running = true;
    while (Running)
    {
        Event Event;
        memset((void*)&Event, 0, sizeof(Event)); // this one doesnt help either

        while (App.GetEvent(Event))
        {        
            if (Event.Type == Event::Closed)
                Running = false;
       
            if ((Event.Type == Event::KeyPressed) && (Event.Key.Code == Key::Escape))
                Running = false;
        }

        App.Display();
    }

    return EXIT_SUCCESS;
}



Linux 2.6.31-6.slh.2-sidux-amd64 #1 SMP PREEMPT x86_64 GNU/Linux
Code::Blocks SVN 5911
SFML 1.5


I have added sfml-window.so and sfml-system.so to the linker libraries, in that order.
I also added SFML_DYNAMIC to the #defines section
Title: GetEvent always returns true
Post by: Laurent on December 31, 2009, 12:03:53 am
This code looks ok.

I don't know, maybe you have a configuration issue. For example, I have a similar problem with my keyboard: the OS sees it as a joystick (in addition to a keyboard), and SFML is stuck in the event loop generating random joystick events. I still haven't found why my Debian does that.
Title: GetEvent always returns true
Post by: drobole on December 31, 2009, 01:51:17 am
Quote from: "Laurent"
This code looks ok.

I don't know, maybe you have a configuration issue. For example, I have a similar problem with my keyboard: the OS sees it as a joystick (in addition to a keyboard), and SFML is stuck in the event loop generating random joystick events. I still haven't found why my Debian does that.


Ok, I'll try to investigate that. Thanks for the replies
Title: GetEvent always returns true
Post by: drobole on December 31, 2009, 02:45:30 am
Just a little update:

It turned out that it was the JoyMoved event that bombarded my loop, and I don't have a joystick connected to the PC. I seem to remember reading about this somewhere a long time ago but I cant find it right now.

Anyway, if anyone else using linux have this problem when they disconnect the joystick it would be interesting to know.


[edit]
Using the jstest utility from the joystick package it turns out that the /dev/input/js0 device thinks it detects a joystick, even though it is the mouse:
Code: [Select]

# jstest /dev/input/js0
Driver version is 2.1.0.
Joystick (Microsoft Microsoft® SideWinder™ X5 Mouse) has 36 axes (X, Y, Z, Rx, Ry, Rz, Throttle, Rudder, Wheel, Hat0X, Hat0Y, Hat1X, (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null), (null))
and 7 buttons (BtnThumbL, BtnThumbR, LeftBtn, RightBtn, MiddleBtn, SideBtn, ExtraBtn).
Testing ... (interrupt to exit)
...


I guess this is a kernel or driver issue, as you suggested
Title: GetEvent always returns true
Post by: Laurent on December 31, 2009, 11:37:05 am
I'm glad to see that I'm not the only one, and I hope that someone will find a fix for this problem :?