【发布时间】:2018-05-25 10:44:43
【问题描述】:
我的程序出现错误,在尝试运行此功能后,unity 崩溃了。作用是将Texture2D转为Image
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);
}
}
Unity(编辑器和独立应用程序)刚刚崩溃并且没有显示任何错误。仅显示此window。
我只能考虑内存访问冲突(但应用程序没有显示任何异常)
如果我删除该功能,程序将正常运行
我在 EmguCV(桌面版)中使用 Unity 个人版。
【问题讨论】: