SFML community forums

Help => General => Topic started by: Azaral on May 14, 2013, 06:59:18 pm

Title: Weird error - SFML2.0
Post by: Azaral 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
Title: Re: Weird error - SFML2.0
Post by: Laurent on May 14, 2013, 07:03:43 pm
Read the event tutorial carefully, especially the red paragraph.
Title: Re: Weird error - SFML2.0
Post by: eXpl0it3r 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.
Title: Re: Weird error - SFML2.0
Post by: Azaral 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!
Title: Re: Weird error - SFML2.0
Post by: Azaral 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.
Title: Re: Weird error - SFML2.0
Post by: zsbzsb 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.
Title: Re: Weird error - SFML2.0
Post by: Cornstalks 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