Skip to content

Commit

Permalink
ios fix suspend crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
hexate committed Mar 27, 2012
1 parent 7aa86ee commit e55c93d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions MonoGame.Framework/iOS/iOSGamePlatform.cs
Expand Up @@ -69,6 +69,7 @@ 1. Definitions
using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;

using MonoTouch.Foundation;
using MonoTouch.OpenGLES;
Expand All @@ -89,6 +90,7 @@ class iOSGamePlatform : GamePlatform
private OpenALSoundController soundControllerInstance = null;
private NSTimer _runTimer;
private bool _isExitPending;
private bool _isPaused;

public iOSGamePlatform(Game game) :
base(game)
Expand Down Expand Up @@ -194,7 +196,7 @@ private void Tick()
try {
if (PerformPendingExit())
return;
if (IsPlayingVideo)
if (IsPlayingVideo || _isPaused)
return;

// FIXME: Remove this call, and the whole Tick method, once
Expand All @@ -205,7 +207,7 @@ private void Tick()
_viewController.View.MakeCurrent();
Game.Tick ();

if (!IsPlayingVideo)
if (!IsPlayingVideo && !_isPaused)
_viewController.View.Present ();

PerformPendingExit();
Expand Down Expand Up @@ -240,15 +242,16 @@ public override bool BeforeDraw(GameTime gameTime)
{
// Update our OpenAL sound buffer pools
soundControllerInstance.Update();
if (IsPlayingVideo)
if (IsPlayingVideo || _isPaused)
return false;
return true;
}

public override bool BeforeUpdate(GameTime gameTime)
{
if (IsPlayingVideo)
if (IsPlayingVideo || _isPaused)
return false;

return true;
}

Expand Down Expand Up @@ -305,12 +308,15 @@ private void StopObservingUIApplication()

private void Application_WillEnterForeground(NSNotification notification)
{
// Already handled in Application_DidBecomeActive. See below for IsActive state change.
// pauses the game's update and draw cycles so GL calls are not made
// when the application is in the background.
_isPaused = false;
}

private void Application_DidEnterBackground(NSNotification notification)
{
// Already handled in Application_WillResignActive. See below for IsActive state change.
// start allowing the update and draw cycles again when the app continues running.
_isPaused = true;
}

private void Application_DidBecomeActive(NSNotification notification)
Expand Down

4 comments on commit e55c93d

@kjpou1
Copy link

@kjpou1 kjpou1 commented on e55c93d Mar 27, 2012

Choose a reason for hiding this comment

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

kungfubanana

I was thinking the same thing for using Game.IsActive instead of introducing a new variable in the class.

Did we work out the Game.IsActive issue on iOS? I know we did for Mac.

@hexate
Copy link
Owner Author

@hexate hexate commented on e55c93d Mar 27, 2012

Choose a reason for hiding this comment

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

Like I said I'm not sure how you guys want to solve it. I know the easiest way I could see immediately was to put it in the BeforeUpdate() and BeforeDraw() functions, and Game.IsActive was not already used in there which I thought was strange. If using Game.IsActive is better, then it should be used, I'm just not familiar with how the vars are used in there.

@azchohfi
Copy link

Choose a reason for hiding this comment

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

This fix is working for me! Please commit!

@hexate
Copy link
Owner Author

@hexate hexate commented on e55c93d Mar 29, 2012

Choose a reason for hiding this comment

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

looks like your fix works (and is much prettier). I reverted the change in my fork.

thanks guys!

Please sign in to comment.