Direct Rendering Bug

Category: 

Google Cardboard and Unity3D generally work very well together, but with some PCs it comes to a problem with Direct Rendering. To use Image Effects outside of the editor, you have to set Direct Render to false, but if you then run the game inside the editor, unity will crash.

Solution

As so often, there are several approaches to solve the problem. One could look into the code of StereoController script to fix the problem where it occurs. But this might be a lot of work. So we take the simple approach: We keep Direct Render set and write a little script to set it to false, when we are outside the editor. This script should be attached to the camera, which holds the StereoController.
using UnityEngine;
using System.Collections;

public class RenderFix : MonoBehaviour {
  void Start () {
    #if !UNITY_EDITOR
    GetComponent<StereoController>().directRender = false;
    #endif
  }
}

Or if you prefer to use Javascript:

#pragma strict

function Start () {
  #if !UNITY_EDITOR
  GetComponent<StereoController>().directRender = false;
  #endif
}

When we start the game inside the editor, our script does nothing and Direct Render remains true. If we start it outside the editor, like on our Android smartphone, the script sets Direct Render to false and our Image Effects also work on Android.