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

Author Topic: [SOLVED] Window Crashes After ~10 Sec / Console Continues to Run  (Read 3192 times)

0 Members and 1 Guest are viewing this topic.

j_oxford

  • Newbie
  • *
  • Posts: 3
    • View Profile
[SOLVED] Window Crashes After ~10 Sec / Console Continues to Run
« on: September 20, 2019, 02:56:05 am »
Want to preface this by saying that I just started learning SFML and C++ this week, so apologies if I'm missing something obvious! Also, sorry for the long post, but I've been going in circles on this issues nonstop. Normally I am able to figure out the issue, but I've combed through tutorials, docs, and dozens of forum posts to no avail.

The issue is that I have made a racing game that runs perfectly fine on my computer (it compiles, builds, and the resulting .exe runs just fine on my laptop and my desktop). I wanted my friend to try it, so I uploaded everything to Git. He downloaded it, and the game runs for roughly 10 seconds, then it freezes and eventually crashes. I left the console up so that he could see it, and he told me that after it crashes the console still logs the frame-counter that I put in. However, when he double clicks on the console window, it stops.

I can't replicate the issue, but I have managed to create something similar by clicking outside of the window (which freezes the window, but not the console -- i.e. the loops are still running, but the rendering has stopped).

Here's what I'm using:
- Visual Studio 19
- SFML (2.5.1 32 Bit for Visual C++ 17) -- Not sure if the issue is here seeing as I'm on VS19

Here's what I've checked so far:
- All of my linkers/libs/etc are good, and I've triple checked them. It builds just fine.
- He has all of the .dll's and files he needs to run the program (he's streamed his desktop so I could see and verify)
- His openGL is up to date
- We're on different types of Windows 10 (He's on pro, I'm on home). However, I had another friend using win 10 home try it and it broke as well.
- It runs on my laptop (win 10 home) and my desktop (win 7 home) with zero issues other than the crash when I click out of the game window.
- Nothing comes out when I run the files in debug inside VS -- no errors.
- It's not screen resolution related as far as I can tell as we have the same screen size
- I've checked more things, I know, but I can't remember them all.
- EDIT: I have also rebuilt and had him test multiple times

tl;dr
- Friend downloads game, and extracts the zip
- Friend clicks on .exe to run the game
- Game opens; all images load, everything displays as it should; controls work; player moves
-After ~10 seconds, the window showing the game 'stops working', but the console continues to spit out everything as normal, in the correct order (I've placed debug stuff everywhere), it keeps running but the rendering stops.
- Friend double clicks on console and the console stops. ESC input still closes the program.
- I open the game, runs and plays just fine, never crashes or freezes. Only when I click to another program does it crash (but only the window crashes -- console continues spitting out cout information that pops up when certain functions run)

I know I should post code, but there's not anything pointing to where I should be looking and the game is running fine on my end. So as far as issues with the game itself, nothing is 'failing'. So I don't really know what code to post. At this point, it seems like some sort of rendering issue, but I'm not entirely certain  :-\

Any help or pointers in the correct direction would be helpful. Let me know if there's something in my code you want to see.

Here's the GitHub if downloading the game and seeing it yourself helps:
https://github.com/justin-oxford/Formula-Racing
« Last Edit: September 21, 2019, 02:57:14 am by j_oxford »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Window Crashes After ~10 Sec / Console Continues to Run
« Reply #1 on: September 20, 2019, 07:45:27 am »
Sounds like you aren't handling events. You need to have an event loop, otherwise the OS will mark your window as unresponsive.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

j_oxford

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Window Crashes After ~10 Sec / Console Continues to Run
« Reply #2 on: September 20, 2019, 12:28:27 pm »
Sounds like you aren't handling events. You need to have an event loop, otherwise the OS will mark your window as unresponsive.
EDIT: Found another forum post talking about the formatting, so I adjusted my pseudo code.

Thanks for the tip! I remember coming across something like this at one point, but I wasn't sure how to implement it properly, or if it was what I needed.

Would it be something to the effect of:

// game loop
Event = someEventToPoll;
while (window is open) { // game loop I already have in place
      while (poll event => someEventToPoll) { // new loop to poll an event
            // check for close fcn
      }
      // game fcns, etc. (i.e. everything already in my game loop):
            // input();
            // ...;
            // draw();
}
 

I remember seeing something vaguely resembling that (obviously with proper syntax, but I think you get the idea). If so, is this fixing the problem because it's 'polling' an event (someEventToPoll) every time the game loop runs - thus having Windows view the program as 'running'? Does this explain why it immediately fails on some machines and not others, though? (I'm still learning how a program interacts with the machine and OS -- since I came from web dev and don't know many of the nuances of this kind of programming -- so knowing why helps a bunch!)

I'm going to give this a try and see if it works! Thanks so much!
« Last Edit: September 20, 2019, 12:32:58 pm by j_oxford »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Window Crashes After ~10 Sec / Console Continues to Run
« Reply #3 on: September 20, 2019, 12:36:46 pm »
The "detection" of unresponsive windows was only added in newer Windows versions. I'd have assumed it was on Win7 already, but not sure.

Yes, your pseudo code makes sense.
I also recommend reading through the SFML tutorials, which will explain many details: https://www.sfml-dev.org/tutorials/2.5/
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

j_oxford

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Window Crashes After ~10 Sec / Console Continues to Run
« Reply #4 on: September 21, 2019, 02:56:45 am »
Just heard back from my friend, and everything is running fine! It's also no longer crashing on my own machine when tabbing out. Thanks so much for the pointers and info!!

Just a note on the OS, the crashing issue wasn't consistent across OS's/Versions which was odd -- it ran on one Win10 machine but crashed on another. That's part of what made diagnosing the issue so difficult is that there wasn't really anything consistent to test against -- at least that I could find.

Nonetheless, adding the pollEvent solved all of the issues I mentioned.