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

Author Topic: Weird error - SFML2.0  (Read 2794 times)

0 Members and 1 Guest are viewing this topic.

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Weird error - SFML2.0
« on: May 14, 2013, 06:59:18 pm »
So, I'm getting this weird error. I have a loop that runs the program and I exit the loop by setting a bool to false when escape is pressed. However, when I move my mouse to a general location, located near the upper left hand corner of the screen the program will exit on its' own. It doesn't throw any error message in release or in debug mode. If I take out the key checking part, it does not occur.

I'm using SFML 2.0 , using visual studio 2010 express, windows 7 OS

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Weird error - SFML2.0
« Reply #1 on: May 14, 2013, 07:03:43 pm »
Read the event tutorial carefully, especially the red paragraph.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Weird error - SFML2.0
« Reply #2 on: May 14, 2013, 07:04:06 pm »
I'm to 99% sure, that you're doing the checking wrong, i.e. you only check what the key is pressed, but not if it's actually pressed. ;)
But without the code we can't help you further and what Laurent said.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Re: Weird error - SFML2.0
« Reply #3 on: May 14, 2013, 07:53:23 pm »
Yes, you were correct. I was just checking what key was pressed instead of first checking if a key was pressed at all. I changed it and now it works fine. Thanks you!

Azaral

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Re: Weird error - SFML2.0
« Reply #4 on: May 14, 2013, 07:59:53 pm »
As an aside, I iterated through all possible mouse position and anytime the mouse x value was equal to 58 is when the exit occurred.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Weird error - SFML2.0
« Reply #5 on: May 14, 2013, 10:11:50 pm »
As an aside, I iterated through all possible mouse position and anytime the mouse x value was equal to 58 is when the exit occurred.

It is not always going to be "58". If could be anything, when you don't check the event type first it leads to undefined behavior. That undefined behavior will vary depending on the compiler/os and other variables. That's why its best to avoid undefined behavior.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Cornstalks

  • Full Member
  • ***
  • Posts: 180
    • View Profile
    • My Website
Re: Weird error - SFML2.0
« Reply #6 on: May 15, 2013, 01:01:38 am »
It is not always going to be "58". If could be anything, when you don't check the event type first it leads to undefined behavior. That undefined behavior will vary depending on the compiler/os and other variables. That's why its best to avoid undefined behavior.
I don't know if I'd word that so strongly ("leads to undefined behavior"). If you actually read the C++ standard, it doesn't say it (accessing "inactive" members of a union) leads to undefined behavior (it also doesn't explicitly say it doesn't lead to undefined behavior).

But yes, it's certainly problematic :D