Hey everyone!
I've been working on a game and whenever I close the SFML Window, a.k.a. when the game loop ends, the window closes but the console windows stays and I get a "the program is not responding" error from windows.
By manually attaching a debugger I found this only error message:
Unhandled exception at 0x777122D2 (ntdll.dll)
After googling a bit I found out that it may have to do with my RenderWindow being static, I changed that but it still crashes.
Here is the relevant code (Main):
using System;namespace GameProject
{#if WINDOWS || LINUX class Program
{ public static SFML
.System.Clock gameClock
; [STAThread
] static void Main
() { StateManager Game
= StateManager
.Instance; //The instance is created here. Game
.Initialize(); Game
.LoadContent(); gameClock
= new SFML
.System.Clock(); float gameTime
; while(!StateManager
.Ended) { //When the close button is clicked, this becomes true gameTime
= gameClock
.ElapsedTime.AsMicroseconds()/1000f
; gameClock
.Restart(); Game
.Update(gameTime
); Game
.Draw(); } Game
.UnloadContent(); gameClock
.Dispose(); Environment
.Exit(0); } }#endif} The Constructor of the StateManager looks like this:
public void Initialize
() { Window
= new RenderWindow
(new VideoMode
(1280,
720),
"Project-F", Styles
.Close); Window
.SetVerticalSyncEnabled(false); Window
.GainedFocus += new EventHandler
(OnGainedFocus
); Window
.LostFocus += new EventHandler
(OnLostFocus
); Window
.Closed += new EventHandler
(OnClosed
); Window
.SetVisible(true); } This just sets Ended to true
private void OnClosed(object sender, EventArgs e) {
Ended = true;
}
And this is the UnloadContent method of the StateManager:
public void UnloadContent() {
_currentState.UnloadContent();
Window.Close();
Window.Dispose();
}
_currentState.UnloadContent(); just disposes a few textures.
Additionally I could track the crash down to in between these two lines:
gameClock.Dispose();
Environment.Exit(0);
Any idea why that happens?
Thank you in advance.
PS: Here the full code of StateManager.cs if needed:
https://pastebin.com/sa0apq0V