Unity3d EmguCV导致的统一崩溃

Unity3d EmguCV导致的统一崩溃,unity3d,emgucv,Unity3d,Emgucv,我的程序出错,unity在尝试运行此函数后崩溃。功能是将纹理2D转换为图像 void SetTextureDefault() { try { Texture2D currentTexture = new Texture2D(CameraTexture.width, CameraTexture.height); currentTexture.SetPixels(CameraTexture.GetPixels()); currentTe

我的程序出错,unity在尝试运行此函数后崩溃。功能是将纹理2D转换为图像

void SetTextureDefault()
{
    try
    {
        Texture2D currentTexture = new Texture2D(CameraTexture.width, CameraTexture.height);
        currentTexture.SetPixels(CameraTexture.GetPixels());
        currentTexture.Apply();

        // Asuming leftBackground and rightBackground of Image<Bgra, byte> exist

        if (leftBackground == null || rightBackground == null)
        {
            using (var ms = new MemoryStream(currentTexture.EncodeToPNG()))
            {
                leftBackground = new Image<Bgra, byte>(new Bitmap(ms));
            }
        }
        else
        {
            rightBackground.Bytes = leftBackground.Bytes = currentTexture.EncodeToPNG();
        }
    }
    catch (Exception err)
    {
        Debug.Log(err.StackTrace);
    }
}
void settexturedfault()
{
尝试
{
Texture2D currentTexture=新的Texture2D(CameraTexture.width、CameraTexture.height);
currentTexture.SetPixels(CameraTexture.GetPixels());
currentTexture.Apply();
//A图像存在左背景和右背景
如果(leftBackground==null | | rightBackground==null)
{
使用(var ms=new MemoryStream(currentTexture.EncodeToPNG())
{
leftBackground=新图像(新位图(毫秒));
}
}
其他的
{
rightBackground.Bytes=leftBackground.Bytes=currentTexture.EncodeToPNG();
}
}
捕获(异常错误)
{
Debug.Log(err.StackTrace);
}
}
Unity(编辑器和独立应用程序)刚刚崩溃,没有显示任何错误。只展示这个

我只能考虑内存访问冲突(但应用程序没有显示任何例外)

如果我删除该功能,程序将正常运行


我正在将Unity personal与EmguCV(桌面版)一起使用。

导致应用程序崩溃的问题是:

leftBackground = new Image<Bgra, byte>(new Bitmap(ms));
leftBackground=新图像(新位图(ms));
在构建一个包含函数的新dll并将其附加到unity并运行之后,问题得到了解决。 奇怪的