NoesisException: Calling thread (7516) doesn't have access to this object (5556)
Posted: 03 Dec 2017, 13:35
I've come across an annoying error. Apparently I'm calling some code from another thread.
Setup
I've got a GameManager (Monobehaviour) class which holds a bunch of commands (can be added from anywhere in the code) which need to be executed on various objects. One of those commands is the switching of a view. When the Update() method is called on the GameManager, all the commands which were stored are getting called on the listeners.
One of those listeners is my viewmodel for my main view. It listens for a change of view command and executes the code to load a xaml from code.
Classes
MainViewModel
GameManager (relevant part)
Stacktrace
Setup
I've got a GameManager (Monobehaviour) class which holds a bunch of commands (can be added from anywhere in the code) which need to be executed on various objects. One of those commands is the switching of a view. When the Update() method is called on the GameManager, all the commands which were stored are getting called on the listeners.
One of those listeners is my viewmodel for my main view. It listens for a change of view command and executes the code to load a xaml from code.
Classes
MainViewModel
Code: Select all
public class MainVM : BaseVM, IChangeUIViewCommand
{
#region Private Fields
private Panel _contentContainer;
#endregion Private Fields
#region Public Constructors
public MainVM(Panel contentContainer) : base()
{
_contentContainer = contentContainer;
GameManager.Subscribe(this, Enums.CommandType.ChangeUIView);
}
#endregion Public Constructors
#region Public Methods
public void ChangeUI(Enums.UILevel uiLevel)
{
object usercontrol = null;
_contentContainer.Children.Clear();
var xamlLocation = "";
switch (uiLevel)
{
case Enums.UILevel.None:
break;
case Enums.UILevel.Login:
xamlLocation = "Assets/UI/Views/Login.xaml";
break;
case Enums.UILevel.CharacterSelection:
xamlLocation = "Assets/UI/Views/CharacterSelection.xaml";
break;
case Enums.UILevel.CharacterCreation:
xamlLocation = "Assets/UI/Views/CharacterCreation.xaml";
break;
case Enums.UILevel.Ingame:
xamlLocation = "Assets/UI/Views/Ingame.xaml";
break;
case Enums.UILevel.Loading:
xamlLocation = "Assets/UI/Views/Loading.xaml";
break;
}
usercontrol = Noesis.GUI.LoadXaml(xamlLocation);
if (usercontrol != null)
_contentContainer.Children.Add(usercontrol);
}
#endregion Public Methods
}
Code: Select all
private void Update()
{
while (_commandQueue.Count > 0)
{
var command = _commandQueue.Dequeue();
if (command.IsNetworkCommand)
ExecuteNetworkCommand(command);
else
ExecuteLocalCommand(command);
command.Recycle();
}
}
private void ExecuteLocalCommand(Command command)
{
var commandListenersByType = _commandListeners[command.CommandType];
for (int j = 0; j < commandListenersByType.Count; j++)
command.Execute(commandListenersByType[j]);
}
Code: Select all
PulatiaUI.CharacterSelection:.ctor() (at Assets/UI/Views/CharacterSelection.xaml.cs:36)
System.Runtime.CompilerServices.ExecutionScope:lambda_method(ExecutionScope)
Noesis.Extend:CreateInstance(IntPtr, IntPtr) (at Assets/NoesisGUI/Plugins/API/Core/NoesisExtend.cs:3887)
Noesis.GUI:Noesis_LoadXaml(String)
Noesis.GUI:Noesis_LoadXaml_(String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:262)
Noesis.GUI:LoadXaml(String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:120)
Assets.UI.ViewModels.MainVM:ChangeUI(UILevel) (at Assets/UI/ViewModels/MainVM.cs:90)
Pulatia.Network.Common.Commands.ChangeUIViewCommand:Execute(ICommandListener)
GameManager:ExecuteLocalCommand(Command) (at Assets/Scripts/Managers/GameManager.cs:141)
GameManager:Update() (at Assets/Scripts/Managers/GameManager.cs:116)