【问题标题】:Unity UpdateExternalTexture from MovieTexture windows crash来自 MovieTexture 窗口的 Unity UpdateExternalTexture 崩溃
【发布时间】:2015-12-01 17:54:50
【问题描述】:

我正在尝试用SpriteRenderer 对象播放MovieTexture 对象。 我的代码在 OSX 上运行良好。

崩溃我的 windows 7 导出的游戏,并在 windows 7 的 Unity 编辑器中播放模式。

我确定currentTexture.UpdateExternalTexture() 调用会导致崩溃,但我不知道为什么。

谁能解释为什么这不起作用或如何调试它? Unity 日志文件没有包含任何有用的信息,只有消息 Crashed.

这是我正在使用的

using UnityEngine;
using System.Collections;

public class FMAC_VideoPlayer : MonoBehaviour {

public string animationName = "escalator";

MovieTexture movieTexture;
Texture2D currentTexture;
SpriteRenderer spriteRenderer;
Sprite sprite;

void Start () 
{
    movieTexture = Resources.Load (animationName) as MovieTexture;

    currentTexture = new Texture2D(movieTexture.width, movieTexture.height);
    currentTexture.UpdateExternalTexture(movieTexture.GetNativeTexturePtr());

    spriteRenderer = GetComponent<SpriteRenderer> ();
    sprite = Sprite.Create (currentTexture, new Rect(Vector2.zero, new Vector2(movieTexture.width, movieTexture.height)), new Vector2(0.5f, 0.5f));
    spriteRenderer.sprite = sprite;

    movieTexture.Play();
}
}

想法?

更新

我有 Debug.Log() 编辑了打印指针地址的本机纹理指针(例如 556409680 ),所以它似乎不是 NULL。

【问题讨论】:

    标签: c# windows graphics unity3d texture2d


    【解决方案1】:

    在 Unity docs for GetNativeTexturePtr() 上我找到了这一行:

    在不支持本机代码插件的平台上,此函数始终返回 NULL。

    这可能是问题所在,将null 作为参数传递会导致崩溃。至于如何修复它,我会说测试它的值是null 并运行保证工作的替代代码。

    【讨论】:

    • 这是一个很好的猜测,我只是尝试检查 null 但它似乎有一个有效值。我已经用这个更新了这个问题。
    • 我不太擅长低级编程,但我相信指针可以指向空值。尝试.ToInt32() 获取指针的值。
    • 又是好点。试过了,它打印的值和以前一样。所以我认为 toInt32() 值是在这种类型的对象的情况下默认打印的值。
    • 我真的没有更多的想法,你试过Unity stackexchange吗?他们也许可以就它的统一端提供一些提示。
    • 感谢您的提示。我不知道有一个 Unity 特定的堆栈交换。我发布了统一的答案,现在在 Unity Stack Exchange 上发布。
    猜你喜欢
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 2014-05-14
    • 2014-06-22
    • 1970-01-01
    • 2018-06-14
    相关资源
    最近更新 更多