Fixing issue #2236 in WindowsGL #2255

Closed
wants to merge 1 commit into
from

Projects

None yet

5 participants

@danShumway
GamePlatform.cs
Line 284: Removed IsActive = true;

OpenTKGamePlatform.cs
Line 145: Runloop - added IsActive = true;

Fixes issue #2236 - Game Deactivate fired during startup.
Makes IsActive only get set to true after initialization when the game actually becomes active.

Signed-off-by: Daniel Shumway shumway.danny@gmail.com

@danShumway danShumway In WindowsGL() ----->
	GamePlatform.cs
	Line 284: Removed IsActive = true;

	OpenTKGamePlatform.cs
	Line 145: Runloop - added IsActive = true;

Fixes issue #2236 - Game Deactivate fired during startup.
Makes IsActive only get set to true after initialization when the game actually becomes active.

Signed-off-by: Daniel Shumway <shumway.danny@gmail.com>
4dce25a
@mgbot
MonoGame member

Can one of the admins verify this patch?

@mgbot
MonoGame member

Can one of the admins verify this patch?

@totallyeviljake

this is mine to verify...

@tomspilman
MonoGame member

@mgbot test

@mgbot
MonoGame member

Test PASSed.
Refer to this link for build results: http://build.monogame.net/job/PullRequestTester/607/

@totallyeviljake

Deactivate is still be invoked during the first run. This happens in the ResetWindowBounds(bool) method of OpenTKGamePlatform. This appears to still be a problem with lazy window creation. The Game Initialize() method sets the platform to be active after Initialize is done initializing the graphics device service. That's also when LoadContent is invoked.

Technically the IsActive flag should not be set to true until the main window is presented and is visible.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.game.isactive.aspx

Setting it to true before content is loading is a violation of how the XNA docs describe the IsActive flag.

This PR does not fix #2236.

@danShumway

In the interest of me possibly figuring out where I'm going wrong, what tests did you run to get OnDeactivated to trigger? With the submitted change, I haven't gotten any of my test projects to replicate the issue anymore, either by messing around in OnDeactivated or by debugging and manually stepping through the code and seeing what gets called.

IsActive is set to false within ResetWindowBounds primarily as (according to the comments at least) a safety measure to prevent games from crashing if a developer puts too much logic into his/her Draw call. Removing IsActive=false from ResetWindowBounds (in my test cases at least), didn't cause any problems, but in the interest of not accidentally breaking someone's code that might already work, I left it as is.

Instead, I remove IsActive=true from its original position (before initialization even starts) and move it to after the last call to ResetWindowBounds, right before Window.Run(). It's obviously quite possible that I missed something, but when I trace through the code, my tests show IsActive being set to true after LoadContent and base.Initialize finishes firing off, and right before the main Update/Draw loop start getting called.

OnDeactivate is only thrown when IsActive changes from true to false, not every time it's set to false, so while ResetWindowBounds still sets IsActive to false, it shouldn't be triggering any events when it does so, at least if I understand the code correctly.

@totallyeviljake

The problem is that the IsActive is set to true before the first window reset occurs, and so IsActive is set to false, which raises the OnDeactivate event. Your two changes do not affect this behavior.

but in the interest of not accidentally breaking someone's code that might already work

This is the biggest rub of these bugs. You will have to break where someone else has worked around this "feature" as the feature is clearly incorrectly implemented per the XNA lifecycle description of Game.IsActive. I don't like breaking existing game compatibility either, but in this case, it will have to happen. There are not many games in production that use the OpenGL version of MG. I think a ham-fisted approach is tolerable in this case.

@totallyeviljake

I setup the activate and deactivate event handlers in the ctor of my drawable component. That way I don't miss any lifecycle events on the game.

https://github.com/Cocos2DXNA/cocos2d-xna/blob/master/cocos2d/platform/CCApplication.cs

Line 49. that's where we start to get events from the Game.

@danShumway

Makes sense; thanks so much for the feedback.

I'll take another look at the code. I haven't run a huge number of tests, but it's possible then that IsActive = false could just be removed from ResetWindowBounds while only ever affecting the edge cases from incorrect behavior. That wouldn't fix IsActive getting set to true early though. I'm not sure where that's happening, but I'll look around and see if I can find it.

@tomspilman
MonoGame member

@thefiddler - Do you think this is fixed with your latest changes to WindowsGL?

@thefiddler

I don't think so. I haven't tested this yet but it's on my todo list.

@tomspilman
MonoGame member

This was never figured out and we've since decided to drop OpenTK. Closing this.

@tomspilman tomspilman closed this Apr 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment