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

Author Topic: SFML2 -- Possible Bug? Crashing when sf::Mouse::getPosition().x equals 36  (Read 3292 times)

0 Members and 1 Guest are viewing this topic.

darthnoid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Hey there. So I've read through the documentation for the sf::Mouse class and scoured through google and haven't come up with anyone even mentioning they are having the same problem.

In order to ensure the problem was not with another factor I made a simple program that does nothing but draw a window, and output to the console via cout << the X,Y Coords of the mouse cursor relative to the RenderWindow...if I start from the left side of the Window in the negative X's and move right, the last number in the console that prints is 35.  If I start from the right and work my way towards the left edge of the window it crashes and the last printed number is 37.

TL;DR is this a bug? Anyone else experience the same thing?  I've experienced it on my desktop PC and my bootcamped MacBook Pro.

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;

int main()
{
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "Double-yew tee eff ITZ BROKEN!");

int mouseX, mouseY;


while(Window.isOpen())
{
     sf::Event event;
     while(Window.pollEvent(event))
{
        if(event.type == sf::Event::Closed)
               Window.close();
}
mouseX = sf::Mouse::getPosition().x;
mouseY = sf::Mouse::getPosition().y;

Window.clear();
Window.display();
cout << "MouseX: " << mouseX << "\tMouseY: " << mouseY << endl;

}

return 0;
}

 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML2 -- Possible Bug? Crashing when sf::Mouse::getPosition().x equals 36
« Reply #1 on: September 14, 2012, 02:06:19 am »
I do not experience anything like that (with MinGW 4.7).

You nee to provide specific information on your used compiler, SFML version and how you linked things.
Also what does the crash say?

Are you sure you're not mixing debug and release modes?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

darthnoid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML2 -- Possible Bug? Crashing when sf::Mouse::getPosition().x equals 36
« Reply #2 on: September 14, 2012, 02:15:58 am »
Was using the sfml2-rc currently downloadable from the site.  Was using MiniGW 4.4 and just downloaded 4.7.  I'm going to give that a try.  All library were statically linked. I will double check my settings to make sure that they aren't mixed up.

Oh, and the crash didn't say anything.  It produced no error, it just shut down the program and returned 0.
« Last Edit: September 14, 2012, 02:29:33 am by darthnoid »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML2 -- Possible Bug? Crashing when sf::Mouse::getPosition().x equals 36
« Reply #3 on: September 14, 2012, 02:24:34 am »
Was using the sfml2-rc currently downloadable from the site.  Was using MiniGW 4.4 and just downloaded 4.7.  I'm going to give that a try.  All library were statically linked. I will double check my settings to make sure that they aren't mixed up.
If you're going to use MinGW 4.7 you'll have to recompile SFML on your own, since the RC isn't compiled for 4.7 and you'd run into some mismatches.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

darthnoid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML2 -- Possible Bug? Crashing when sf::Mouse::getPosition().x equals 36
« Reply #4 on: September 15, 2012, 10:33:10 pm »
Alright, I'm still having issues but I just found something interesting.

Still using the release client for SFML2, in Codeblocks.  I've completely uninstalled codeblocks, MinGW, and removed everything SFML2 related from my computer. 

I reinstalled CodeBlocks, it has a default version of MinGW included (I believe is 4.4.1).  I've reset every one of the build options within code blocks and tried using dynamic libraries instead of static (the same result).

HOWEVER.

I copied the code on the getting started page on the SFML2 Tutorial page...the one that just draws a circle. It didn't do it.  I tried commenting out the code related to the shape, and it still worked fine.  I then added an or statement to the window.close if statement in the loop.

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed || event.key.code == sf::Keyboard::Escape)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
        cout << sf::Mouse::getPosition(window).x << endl;
    }

    return 0;
}
 

This causes the program to close and return no error when X is equal to 36.

While this works normally:

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
        cout << sf::Mouse::getPosition(window).x << endl;
    }

    return 0;
}
 

Does anyone have any ideas while this is. I have also tried moving the sf::Keyboard::Escape to it's own else if statement and it still has the same result.  Then if you replace sf::Keyboard::Escape with sf::Keyboard::_____ where ____ = any other keyboard Key all it does is crash at a different X location. A crashes all the way at the left of the Window. Return crashes near the 57 mark somewhere.

Is this really just me? Does anyone have any ideas.  I'm using the correct debug libraries and not mixing them up.

Edit: I just realized that it is not a crash. For some reason, the mouse hitting those coordinates causes the statement to execute that block of code.  So it is executing window.close().  If I change the content  of the block to cout << "derp" << endl; then it will output derp to the command prompt.
« Last Edit: September 15, 2012, 10:38:25 pm by darthnoid »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML2 -- Possible Bug? Crashing when sf::Mouse::getPosition().x equals 36
« Reply #5 on: September 15, 2012, 10:43:56 pm »
Quote
For some reason
Please read the tutorial carefully, the reason is explained there.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML2 -- Possible Bug? Crashing when sf::Mouse::getPosition().x equals 36
« Reply #6 on: September 16, 2012, 02:29:55 pm »
The tutorial states that you have to check if the event has occurred. At the moment you only check if the keycode is the one you want but you don't check if there was a key press/release.

The correct code would be:
if (event.type == sf::Event::Closed || (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) )
    window.close();
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything