I’m currently upgrading my project to latest Development Build for Visual Studio, and I noticed that Exit() doesn’t work.
I have to close the game by pressing x in Console Application (used for debugging purposes) or by ending the process in Task Manager.
Specs: Win10, VS2015, latest Development Build with DesktopGL template.
P.S. How do I unlock FPS? I have had debug button to toggle FPS lock on-off to see how heavy some of my game areas are, but it doesn’t work anymore. Here’s the code I used in 3.5:
I found a workaround.
At start I just set IsFixedTimeStep and Synchronizing to false, apply changes and immediately lock FPS again. That way I can toggle FPS normally, its weird but it works.
You don’t have to call ApplyChanges in your constructor because the GraphicsDevice hasn’t been created yet. And you should make sure to kill your threads before exiting.
No, there is only the main thread, no other threads. Do I have to kill main thread somehow?
And I have had ApplyChanges() after changes because otherwise the FPS unlock / lock doesn’t work for some reason.
I create SoundEffectInstances, so that I can track how many instances of the sound are playing at the same time, and avoid ear rape by not playing same sound too many times in a row.
When I’m done with the Sounds, I get rid of them with
To be clear, “Exiting” works, but the process doesn’t close.
If I run the game in Visual Studio, the game screen / window closes, but when run from .exe it doesn’t,it just freezes.
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
Exiting += Shutdown;
}
public void Shutdown(object sender, EventArgs e)
{
//Checking if Shutdown works, and it does.
Console.WriteLine("Exiting Game")
}
Hmmm.
The good news is that you’re doing everything correctly.
You could pool your SoundEffectInstances since those are objects and disposing them leads to garbage, but that’s a technicality with no relevance to your problem at hand.
The bad news is that, obviously, we’re missing something here since it really should exit when calling Exit(), like your empty project does. Hell, I have a game here using multithreading, async loading and so on and I use Exit() like you do and it works.
So maybe it’s time to take the new project, copy some code over there until it doesn’t stop when calling Exit(). That sounds horrible but at least you’ll find the culprit.
Maybe you can use TaskManager to look at the not-closing game. Attach the debugger to that process and pause execution and see where you are.
You say it exits flawlessly when debugging in VS??
If I have Just My Code enabled, I get
“The application is in break mode, Your app has entered a break sate, but there is no code to show because all threads were executing external code (typically system or framework code).” Also, there are no tasks to display.
I found the problem, it was the game’s code all along.
I got a bright idea to test Exit() at start of the game, before initializing anything, and guess what: it didn’t work.
At this point, I jumped over to Program.cs, because it was the only thing called before the game itself. First, everything looked fine, until I compared my game’s Program.cs to empty project.
For some reason, I had
var game = new Game1();
game.Run();
While empty project had
using (var game = new Game1())
game.Run();
I don’t know what the real difference here is, but I changed my game to match that and it magically worked!