Skip to content

Commit

Permalink
Calling Game.Exit didn't exit the run loop
Browse files Browse the repository at this point in the history
as it only exited if a WM_QUIT message was sent.  Now disposes of the underlying form when Game.Exit is called.  This breaks it out of the run loop.
  • Loading branch information
KonajuGames committed Feb 2, 2015
1 parent 9214a62 commit d6a65c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
11 changes: 6 additions & 5 deletions MonoGame.Framework/Windows/WinFormsGamePlatform.cs
Expand Up @@ -133,8 +133,10 @@ public override void StartRunLoop()
}

public override void Exit()
{
Application.Exit();
{
_window.Dispose();
_window = null;
Window = null;
}

public override bool BeforeUpdate(GameTime gameTime)
Expand Down Expand Up @@ -189,9 +191,8 @@ protected override void Dispose(bool disposing)
_window.Dispose();
_window = null;
Window = null;

Microsoft.Xna.Framework.Media.MediaManagerState.CheckShutdown();
}
}
Microsoft.Xna.Framework.Media.MediaManagerState.CheckShutdown();
}

base.Dispose(disposing);
Expand Down
39 changes: 21 additions & 18 deletions MonoGame.Framework/Windows/WinFormsGameWindow.cs
Expand Up @@ -59,7 +59,7 @@ 1. Definitions

namespace MonoGame.Framework
{
class WinFormsGameWindow : GameWindow
class WinFormsGameWindow : GameWindow, IDisposable
{
internal WinFormsGameForm _form;

Expand Down Expand Up @@ -198,6 +198,11 @@ internal WinFormsGameWindow(WinFormsGamePlatform platform)
_allWindows.Add(this);
}

~WinFormsGameWindow()
{
Dispose(false);
}

private void OnActivated(object sender, EventArgs eventArgs)
{
_platform.IsActive = true;
Expand Down Expand Up @@ -377,7 +382,8 @@ internal void RunLoop()
continue;
}

OnIdle(this, null);
UpdateWindows();
Game.Tick();
}

// We need to remove the WM_QUIT message in the message
Expand All @@ -399,18 +405,6 @@ internal void RunLoop()
while (PeekMessage(out msg, IntPtr.Zero, 0, 0, 1));
}

private void OnIdle(object sender, EventArgs eventArgs)
{
// While there are no pending messages
// to be processed tick the game.
NativeMessage msg;
while (!PeekMessage(out msg, IntPtr.Zero, 0, 0, 0))
{
UpdateWindows();
Game.Tick();
}
}

internal void UpdateWindows()
{
// Update the mouse state for each window.
Expand Down Expand Up @@ -444,11 +438,20 @@ internal void ChangeClientSize(Size clientBounds)

public void Dispose()
{
if (_form != null)
Dispose(true);
GC.SuppressFinalize(this);
}

void Dispose(bool disposing)
{
if (disposing)
{
_allWindows.Remove(this);
_form.Dispose();
_form = null;
if (_form != null)
{
_allWindows.Remove(this);
_form.Dispose();
_form = null;
}
}
}

Expand Down

2 comments on commit d6a65c8

@mgbot
Copy link
Member

@mgbot mgbot commented on d6a65c8 Feb 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.3.0.2006 is now running

@mgbot
Copy link
Member

@mgbot mgbot commented on d6a65c8 Feb 2, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity MonoGame :: Develop (Win) Build 3.3.0.2006 outcome was SUCCESS
Summary: Tests passed: 368, ignored: 6 Build time: 00:15:40

Please sign in to comment.