【问题标题】:System.Runtime.InteropServices.SEHException in UnityEngine.dllUnityEngine.dll 中的 System.Runtime.InteropServices.SEHException
【发布时间】:2015-04-14 08:43:48
【问题描述】:

我正在为 windows phone 8 导入 unity3D 项目。并添加几行代码,这些代码与 c# 代码交互到 unity3D 中 Object(SphereScript) 的事件更改处理程序。

var sphereScript = UnityEngine.Object.FindObjectOfType<SphereScript>();
sphereScript.SphereStateChanged += sphereScript_SphereStateChanged;
sphereScript_SphereStateChanged(sphereScript.IsSphereMoving);

项目编译正常,没有错误,但在手机上运行时,在线出现错误

UnityEngine.Object.FindObjectOfType<SphereScript>();

'System.Runtime.InteropServices.SEHException' 类型的异常发生在 UnityEngine.DLL 中,但未在用户代码中处理。我不知道为什么会发生这个错误。但是当我第一次启动项目时,它要求我找到文件名 UnityEngineObject.cs。我在哪里可以找到这个文件或者我该如何解决这个问题。谢谢。

完整代码的网址http://docs.unity3d.com/Manual/wp8-unity-interaction.html

【问题讨论】:

  • 可以添加抛出异常的堆栈跟踪吗?
  • System.Runtime.InteropServices.SEHException 未被用户代码处理 HResult=-2147467259 消息=外部组件已引发异常。 Source=UnityEngine ErrorCode=-2147467259 StackTrace:UnityEngine.Internal.$Calli.Invoke38(Int32 arg0, IntPtr method) at UnityEngine.Object.FindObjectsOfType(Type type) at UnityEngine.Object.FindObjectOfType(Type type) at UnityEngine.Object。 UnityXamlInteractionExample.MainPage.Unity_Loaded() InnerException 处的 FindObjectOfType[T]():

标签: c# windows visual-studio windows-phone-8 unity3d


【解决方案1】:

在 Unity 5x 中,我遇到了同样的问题。 所以试试这个:

在脚本 SphereScript.cs 中:

重写这个:

public event Action<bool> SphereStateChanged;

到这里:

public static event  Action<bool> SphereStateChanged = delegate { };

接下来,在 Visual Studio 中构建项目后取消注释这些部分代码:

UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); });

private void Unity_Loaded() { }

现在插入 private void Unity_Loaded()

ShareScript.SphereStateChanged += SphereStateChanged;

最后加上这个:

void SphereStateChanged(bool currentSpehreState)
{
    Dispatcher.BeginInvoke(() =>
    {
        SphereStateTextBlock.Text = currentSpehreState ? "Spehre is moving" : "Sphere is stopped";
    });
}

祝你好运,再见:)

【讨论】:

    猜你喜欢
    • 2012-10-20
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 2020-12-25
    • 2014-08-30
    • 2012-09-17
    相关资源
    最近更新 更多