SFML community forums
Help => Window => Topic started 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:
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?
-
Hi
Can you show a minimal and complete piece of code that reproduces this problem?
-
Hi
Can you show a minimal and complete piece of code that reproduces this problem?
#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
-
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.
-
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
-
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:
# 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
-
I'm glad to see that I'm not the only one, and I hope that someone will find a fix for this problem :?