LoginSignup
4
2

More than 3 years have passed since last update.

Unity5.5+WebCamTexture(Android Build)に存在する致命的な不具合(修正済み)

Last updated at Posted at 2017-01-07

普段からUnityを使ってカメラアプリを試作することが多いのですが、ある時期からUnityで作ったAndroidアプリが実行時に頻繁にクラッシュするようになりました。
検証した結果、Unity5.5以降のバージョンとWebCamTextureというシンプルな組み合わせで発生することが分かりました。
この不具合は既にUnity5.5.0p4/5.6.0b3で修正されているのですが、けっこう長い間放置されていたので同じ現象に遭遇した人のために発生条件と回避方法を記事として残しておきます。

不具合の発生条件

以下のようなコードをアタッチしたシーンをロードした状態で、アプリが非活性状態になる(メニューボタンや着信などで)と即落ちます。

using UnityEngine;
Public class Test: MonoBehaviour
{
    WebCamTexture webCamTexture;
    void Start ()
    {
        webCamTexture = new WebCamTexture ();
    }
}

webCamTextureのインスタンスを作成しただけ!
たったこれだけのコードが不具合の原因になります。

回避方法

webCamTextureのインスタンスがPlay()していない状態で存在することが不具合発生のトリガーになるようなので、インスタンス作成時には必ずPlay()をする。

        webCamTexture = new WebCamTexture ();
        webCamTexture.Play ();

webCamTextureの停止と同時にDestroy()する。

        webCamTexture.Stop ();
        Destroy(webCamTexture);
        webCamTexture = null;

以上のことに気を付ければとりあえず不具合を回避できることがわかりました。

修正バージョン

Unity5.5.0p4(リリース: 11 January 2017) / Unity5.6.0b3(リリース: December 23, 2016)でやっと修正されたようです。

  • Android: Fixed crash when reloading or resuming a scene which uses WebCamTexture. (855603, 859268)

https://unity3d.com/jp/unity/beta
https://unity3d.com/jp/unity/qa/patch-releases

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2