I’m trying to set up a plugin for WP8.1 but I’m having some issues.
What I’m trying to do is creating an event from Visual Studio side this way:
public class MyPlugin {
public delegate void myDelegate(string message);
public static event myDelegate OnMyEvent;
[…]
myFunction() {
OnMyEvent(someString);
}
}
And then, use it from Unity side:
void OnEnable() {
PluginNamespace.MyPlugin.OnMyEvent += MyUnityFunction;
}
void OnDisable() {
PluginNamespace.MyPlugin.OnMyEvent -= MyUnityFunction;
}
This have been working fine until I had to use a coroutine inside MyUnityFunction:
private MyUnityFunction(string someString) {
StartCoroutine(MyCoroutineWWW);
}
When I call the coroutine from an event launched from Visual Studio code, it throws the following exception:
{System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at UnityEngineProxy.InternalCalls.MonoBehaviour_CUSTOM_StartCoroutine_Auto(Object self, Object routine)
at UnityEngine.MonoBehaviour.StartCoroutine_Auto(IEnumerator routine)
at UnityEngine.MonoBehaviour.StartCoroutine(IEnumerator routine)}
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Yes, as I said in the first post it is failing when I call the coroutine, but the coroutine fails no matter what I put inside, currently the coroutine only has one line of code (for testing purposes): yield return 0;
The exceptions are enabled, I also attached a screenshot of the exception thrown in the first post.
Used the UnityEngine.WSA.Application.InternalInvokeOnAppThread solution (in my case, it is InvokeOnAppThread, not InternalInvokeOnAppThread, but its ok).