SFML community forums

Help => Window => Topic started by: neufrin on October 22, 2012, 11:21:39 pm

Title: automatically closing window
Post by: neufrin on October 22, 2012, 11:21:39 pm
Hi,
I'm a beginner and I got odd problem with my simple Map Editor: when I move the cursor to the left edge, the window closes itself (exactly between the half and the bottom of the edge). It's really disappointing.
I'm using SFML 2.0 in VS2010 and I do not have this problem in other programs.

here is source code: http://pastebin.com/AUdh9k8v
and here binary, images etc: http://speedy.sh/pdqtc/Release.zip

Any1 could help me?
Title: Re: automatically closing window
Post by: FRex on October 22, 2012, 11:34:08 pm
Just knew this will be that from this description..
By the way, this code is too long. You're supposed to post minimal examples.
while(Window.pollEvent(Event))
                {
                        if(Event.type == sf::Event::Closed || Event.key.code == sf::Keyboard::Escape)
                                Window.close();
                }
 
Event.key.code reads from a union without checking if it's really a key event.
position.x and key.code are stored in the same memory space in that union so you're interpreting x position of mouse as a key code number(so finally you reach the key code for esc when mouse x increases and program closes).