LoginSignup
1
2

More than 5 years have passed since last update.

OculusGoでUnityアプリが落ちる問題と対処方法(Texture2D)

Last updated at Posted at 2018-09-10

はじめに

  • OculusGoアプリをUnityで作成していた際に落ちるようになったので、その原因を調査していました。

現象

  • アプリ上で画像の表示切り替えを繰り返していると落ちる
    • 画像の切り替えを3〜4回すると落ちる(画像の切り替えをしなければ落ちない)
    • PC上では落ちない

原因

  • Texture2D.LoadImage()を複数回実施していたため
    • 読み込んでいる画像データは、JPEG画像をバイナリ化したもの(THETA V静止画、5376×2688)
    • 6〜7回目くらいで落ちる

対策

  • 未使用となったテクスチャを意識的に開放するようにした
LoadImage(6〜7回実行すると落ちる)
    Texture2D tex = new Texture2D(2, 2, TextureFormat.RGBA32, false);
    tex.LoadImage(data);
    _mainScreen.GetComponent<Renderer>().material.mainTexture = tex;
LoadImage(落ちなくなった)
    Texture2D tex = new Texture2D(2, 2, TextureFormat.RGBA32, false);
    tex.LoadImage(data);
    Texture oldTex = _mainScreen.GetComponent<Renderer>().material.mainTexture;
    if (oldTex != null) {
        Behaviour.Destroy(oldTex);
    }
    _mainScreen.GetComponent<Renderer>().material.mainTexture = tex;

考察

  • OculusGoでは、利用できるテクスチャが少ない?
    • システム上で落ちる前まで保持しているテクスチャは6〜7つ(=利用できるテクスチャ)
  • 未使用になったテクスチャは期待通りに開放してくれない
    • 明示的な開放が必要

参考資料

1
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
1
2