I’m trying to run my game on Mac using Xamarin studio. The game compiles fine but then I get the error “AppKit Consistency error: you are calling a method that can only be invoked from the UI thread.”
Has anyone else seen this error?
I’m trying to run my game on Mac using Xamarin studio. The game compiles fine but then I get the error “AppKit Consistency error: you are calling a method that can only be invoked from the UI thread.”
Has anyone else seen this error?
Where is this error occurring? There are things which can only be executed on the primary (UI) thread.
The crash happens in Game1 which is the Game class for my project. Here’s the callstack.
HackPuzzle.Game1..ctor () in /Users/barryhemans/Projects/HackPuzzleMacOSX/HackPuzzleMacOSX/Game1.cs:42
HackPuzzle.AppDelegate.FinishedLaunching (notification={NSConcreteNotification 0x774ae60 {name = NSApplicationDidFinishLaunchingNotification; object = <NSApplication: 0x7b4bc50>; userInfo = {
NSApplicationLaunchIsDefaultLaunchKey = 1;
}}}) in /Users/barryhemans/Projects/HackPuzzleMacOSX/HackPuzzleMacOSX/Main.cs:34
MonoMac.AppKit.NSApplication.NSApplicationMain () in
MonoMac.AppKit.NSApplication.Main (args={string[0]}) in /Users/builder/data/lanes/1977/6db87c53/source/maccore/src/AppKit/NSApplication.cs:94
HackPuzzle.Program.Main (args={string[0]}) in /Users/barryhemans/Projects/HackPuzzleMacOSX/HackPuzzleMacOSX/Main.cs:21
How do I set what thread the game is run on?
Can you show us the code in your Game constructor? What AppKit API are you calling that it is complaining about?
The Game1 constructor is
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
//LeaderBoard.Load ();
Settings.Load ();
graphics.PreferredBackBufferHeight = (int)(768 * 1.0f );
graphics.PreferredBackBufferWidth = (int)(1366 * 1.0f);
GlobalData.Instance().sizeRatio = graphics.PreferredBackBufferHeight / 768.0f;
screenManager = new ScreenManager(this);
LoadingScreen.Load(screenManager, false, null, new MainMenuBackground(), new ControlSelection(NextScreen.MainMenu));
IsMouseVisible = true;
graphics.IsFullScreen = true;
}
I’m not sure what AppKit API I’m calling that is causing the problem. My Main.cs looks like this
using System;
using System.Collections.Generic;
using System.Linq;
using MonoMac.AppKit;
using MonoMac.Foundation;
namespace HackPuzzle
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main (string[] args)
{
NSApplication.Init ();
NSApplication.CheckForIllegalCrossThreadCalls = false;
using (var p = new NSAutoreleasePool ()) {
NSApplication.SharedApplication.Delegate = new AppDelegate ();
NSApplication.Main (args);
}
}
}
class AppDelegate : NSApplicationDelegate
{
Game1 game;
public override void FinishedLaunching (MonoMac.Foundation.NSObject notification)
{
game = new Game1 ();
game.Run ();
}
public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
{
return true;
}
}
}