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

Author Topic: Random crashes?  (Read 2731 times)

0 Members and 1 Guest are viewing this topic.

sircuddles

  • Newbie
  • *
  • Posts: 10
    • View Profile
Random crashes?
« on: February 21, 2013, 02:55:29 am »
I've had this problem and thought it was probably just on my end so I've just sort of been dealing with it.  It seems that randomly, when moving the mouse around, my window simply closes.  This has happened across multiple projects and now with multiple computers, and I'm not sure where the issue lies. 

I recently started coding with a friend (using Git) and he also has the same problem.  We're both using VS12 and got the precompiled packages from exploit's nightly builds.  If you don't move the mouse, there is no problem.  When you do move the mouse, within a few seconds (usually) the window closes on it's own.

I can't seem to find any answers on Google about this particular issue.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Random crashes?
« Reply #1 on: February 21, 2013, 03:34:51 am »
I've had this problem and thought it was probably just on my end so I've just sort of been dealing with it.  It seems that randomly, when moving the mouse around, my window simply closes.  This has happened across multiple projects and now with multiple computers, and I'm not sure where the issue lies. 

I recently started coding with a friend (using Git) and he also has the same problem.  We're both using VS12 and got the precompiled packages from exploit's nightly builds.  If you don't move the mouse, there is no problem.  When you do move the mouse, within a few seconds (usually) the window closes on it's own.

I can't seem to find any answers on Google about this particular issue.
Please read this. Unless you post your code we have no idea what you are doing.

This issue sounds like another issue someone posted and the problem was that they were incorrectly handling events... But without your code we can't help you.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Random crashes?
« Reply #2 on: February 21, 2013, 03:35:05 am »
Show the minimal code that contains the problem, maybe you are doing
if(event.key.code==sf::Keyboard::Escape)window.close();
or similar?
Back to C++ gamedev with SFML in May 2023

sircuddles

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Random crashes?
« Reply #3 on: February 21, 2013, 04:00:09 am »
I didn't post any code because this has happened over many projects since I started using SFML, as I said in the original post.  There isn't any line of code that I can post that I suspect to be the problem, because the problem happens all the time. 

This is the code from the current project main loop (the one that crashes for both me and my partner).  The problem occurs with and without the custom mouse cursor code:

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

                thing.update(gameTime);
                // Horrible update that sets the cursor to the mouse position
                customCursor.update(sf::Vector2f(sf::Mouse::getPosition(gameWindow)));
               
                Board::GetInstance(gameWindow)->draw();
                thing.draw();
                customCursor.draw();

                gameWindow.display();
                gameWindow.clear(sf::Color::White);

                gameTime = gameClock.restart().asSeconds();
    }

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Random crashes?
« Reply #4 on: February 21, 2013, 04:16:44 am »
  if ((gameEvents.type==sf::Event::KeyPressed&&gameEvents.key.code == sf::Keyboard::Escape) || (gameEvents.type == sf::Event::Closed))
is correct.
You can't access any field in event except type without knowing the type first or it's ub.
There's official tutorial about that: http://www.sfml-dev.org/tutorials/2.0/window-events.php
Back to C++ gamedev with SFML in May 2023

sircuddles

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Random crashes?
« Reply #5 on: February 21, 2013, 04:26:45 am »
Initial testing shows that worked, thanks.

So when you try to access something like event.key.code when there is no KeyPressed event, event.key.code is undefined and accessing it results in random garbage? 

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Random crashes?
« Reply #6 on: February 21, 2013, 04:38:08 am »
Yes, but enums are often* same size as int so when mouse x(int) was same value as sf::Keyboard::Escape value of sf::Keyboard::Key enum(here with underlying type int) then the window closed because bits aligned just right to make it look like escape code.

*often = not guaranteed by standard, not reliable, not portable, dependand on compiler, os and settings ect.
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10827
    • View Profile
    • development blog
    • Email
AW: Re: Random crashes?
« Reply #7 on: February 21, 2013, 06:51:00 am »
*often = not guaranteed by standard, not reliable, not portable, dependand on compiler, os and settings ect.
= undefined = not even worth thinking about it = not even worth mentioning ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/