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

Author Topic: automatically closing window  (Read 2417 times)

0 Members and 1 Guest are viewing this topic.

neufrin

  • Newbie
  • *
  • Posts: 3
    • View Profile
automatically closing window
« 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?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: automatically closing window
« Reply #1 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).
Back to C++ gamedev with SFML in May 2023

 

anything