Debugging, Development notes

Unity 5 bug: psychically linked textures on Gear VR

I was creating a simple application for Gear VR in Unity 5.x which was encountering a strange bug where after two seconds it would stop working. Eventually I boiled it down to a minimal reproducing scene that looks like this: 16d9a631a8ba7e82bdf164f87e2e8f78This is a very simple scene: it contains two quads that have two different 4096×4096 textures applied to them, compressed with ETC2 (GLES 3.0). There are no other objects and no active scripts or shaders. Everything else is disabled. When I run it in the Unity editor, the result is what you would expect: the two quads just sit there, with their two different textures, indefinitely. When I build and run the same app on Gear VR on the Note 4, a mysterious and inexplicable event occurs: the app runs correctly for 2 seconds, and then the quad in the back magically changes to have the same texture as the quad in the front! Recall that there are no scripts running. If I disable the quad in the front, this behavior does not occur. Just to be sure, I re-created the quad in front from scratch, to make sure it had no implicit link to the other. The behavior still occurs. After downgrading to Unity 4.x, this behavior vanished and it worked as expected. So it’s most likely some kind of Unity 5 bug. I can only speculate why this occurs. Maybe some internal failure is causing one of the textures to be lost, and so it reverts to the other texture. Maybe it thinks one of the textures has no references, so it’s being garbage collected at the first opportunity. Whatever it is, I should have trusted people who said Unity 5 wasn’t yet safe to use with Gear VR.

Edit: Apparently some people are using Unity 5 for Gear VR with fairly sophisticated projects as shown in this guide. I have no idea what the difference is that’s causing them not to hit the same issue – as far as I know I set up the same way.