Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed some threading issues on iOS #1335

Merged
merged 1 commit into from

5 participants

@Nezz

Fixed some threading issues in iOS achievement and score codes

@mgbot
Collaborator

Can one of the admins verify this patch?

@tomspilman
Owner

@mgbot test

@Nezz

Anything against merging this?

@tomspilman
Owner

Just wanted to test building it at least.

@RayBatts - Can you take a look at this when you get in?

@tomspilman
Owner

@mgbot test

@tomspilman
Owner

Bah... forgot the build server doesn't build for iOS yet.

@Nezz

It compiles for me if you are interested. I have these changes for months in my repo.

@tomspilman
Owner

We really need to have a second person verify. The build server is now that second verification, but iOS builds are not setup yet unfortunately.

@totallyeviljake

i will check it out today.

@totallyeviljake

code review: pass
To test the actual code, we need a gamecenter test account and setup achievements for it? If so, then I can't exercise the code properly yet. None of our games utilize gamecenter. :( sorry

@totallyeviljake totallyeviljake commented on the diff
MonoGame.Framework/iOS/GamerServices/SignedInGamer.cs
((7 lines not shown))
- if (error != null)
- {
- // Retain the achievement object and try again later (not shown).
- }
-
- } );
+ UIApplication.SharedApplication.InvokeOnMainThread(delegate
+ {
+ GKAchievement a = new GKAchievement(achievementId);
+ a.PercentComplete = percentageComplete;
+ a.ReportAchievement(delegate(NSError error)
+ {
+ if (error != null)
+ {
+ // Retain the achievement object and try again later (not shown).
+ }

I see in both cases the error isn't handled, it's just buried. I think we would want to care if the achievement made it or not. That's for another PR though.

@tomspilman Owner

Yea... for another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Nezz

If it compiles nothing can really be wrong :) I just moved the actual calls to the main thread to avoid issues and exceptions thrown by MonoTouch in debug.

@tomspilman
Owner

@totallyeviljake

Oh... lame... I forgot about that issue. Well if it compiles for you it should be pretty safe... the change is really only the UIApplication.SharedApplication.InvokeOnMainThread.

I'm good with merging it.

@tomspilman tomspilman merged commit 16d9bbf into mono:develop3d
@totallyeviljake

@slygamer what happens when XNA fails to push an achievement to XBox Live? Do you get an error notification? I think we need a PR for MG to better handle achievement notification failures.

@Nezz

Xbox Live is part of a different SDK that's under NDA so there's nothing "official" to implement.

@Nezz Nezz deleted the Nezz:ios_threading branch
@KonajuGames
Owner
This was referenced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2013
  1. @Nezz
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 25 deletions.
  1. +35 −25 MonoGame.Framework/iOS/GamerServices/SignedInGamer.cs
View
60 MonoGame.Framework/iOS/GamerServices/SignedInGamer.cs
@@ -298,15 +298,19 @@ public void AwardAchievement( string achievementId )
public void DoAwardAchievement( string achievementId, double percentageComplete )
{
- GKAchievement a = new GKAchievement(achievementId);
- a.PercentComplete = percentageComplete;
- a.ReportAchievement( delegate(NSError error){
- if (error != null)
- {
- // Retain the achievement object and try again later (not shown).
- }
-
- } );
+ UIApplication.SharedApplication.InvokeOnMainThread(delegate
+ {
+ GKAchievement a = new GKAchievement(achievementId);
+ a.PercentComplete = percentageComplete;
+ a.ReportAchievement(delegate(NSError error)
+ {
+ if (error != null)
+ {
+ // Retain the achievement object and try again later (not shown).
+ }

I see in both cases the error isn't handled, it's just buried. I think we would want to care if the achievement made it or not. That's for another PR though.

@tomspilman Owner

Yea... for another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ });
+ });
}
public void AwardAchievement( string achievementId, double percentageComplete )
@@ -321,15 +325,18 @@ public void UpdateScore( string aCategory, long aScore )
{
if (IsSignedInToLive)
{
- GKScore score = new GKScore(aCategory);
- score.Value = aScore;
- score.ReportScore(delegate (NSError error)
- {
- if (error != null)
- {
- // Oh oh something went wrong.
- }
- });
+ UIApplication.SharedApplication.InvokeOnMainThread(delegate
+ {
+ GKScore score = new GKScore(aCategory);
+ score.Value = aScore;
+ score.ReportScore(delegate(NSError error)
+ {
+ if (error != null)
+ {
+ // Oh oh something went wrong.
+ }
+ });
+ });
}
}
@@ -337,13 +344,16 @@ public void ResetAchievements()
{
if (IsSignedInToLive)
{
- GKAchievement.ResetAchivements(delegate (NSError error)
- {
- if (error != null)
- {
- // Oh oh something went wrong.
- }
- });
+ UIApplication.SharedApplication.InvokeOnMainThread(delegate
+ {
+ GKAchievement.ResetAchivements(delegate(NSError error)
+ {
+ if (error != null)
+ {
+ // Oh oh something went wrong.
+ }
+ });
+ });
}
}
Something went wrong with that request. Please try again.