title: QR decode exceptions using ZXing.NET in Unity
body: <p>I'm currently trying to make an application in Unity (for iOS) that allows a user to scan a QR code.
  I am using the ZXing.NET library which has been optimized for Unity.</p>
  
  <p>This is the current decode thread I am using</p>
  
  <pre><code>    void DecodeQR()
     {  
      // create a reader with a custom luminance source
  
        var barcodeReader = new BarcodeReader {AutoRotate=false, TryHarder=false};
  
        while (true)
  
        {
           if (isQuit)
  
              break;
  
           try
  
           {
              string result = "Cry if you see this."; 
  
              // decode the current frame
  
              if (c != null){
  
                  print ("Start Decode!");
                  result = barcodeReader.Decode(c, W, H).Text; //This line of code is generating unknown exceptions for some arcane reason
                  print ("Got past decode!");
              }       
              if (result != null)
              {           
                 LastResult = result;        
                 print(result);
              }
              // Sleep a little bit and set the signal to get the next frame
          c = null;
              Thread.Sleep(200); 
           }
              catch 
              {   
                  continue;
              }
  
        }
      }
  </code></pre>
  
  <p>The execution reaches the "Start Decode!" print statement, but fails to reach the "Got past decode!" statement.</p>
  
  <p>This is because the Decode() method is generating an unknown exception every time, even when the camera is looking at a very clear QR code.</p>
  
  <p>For reference:
  c is of type Color32[] and is generated using WebCamTexture.GetPixels32()
  W, H are integers representing the width and height of the camera texture.</p>
  
  <p>For some reason, I cannot catch a generic Exception within the catch clause, meaning I cannot determine what kind of exception the Decode() method is generating.</p>
  
  <p>EDIT: The code I have used is adapted from the Unity demo available from the ZXing.NET project. I am using the current version of ZXing.NET. I should also mention that I am currently testing this on an iMac, not on an iOS device or the simulator. I have tried running the Unity demo from scratch and I obtain the same result.</p>
  
  <p>This is how the c variable (Color32[]) is updated:</p>
  
  <pre><code>void Update()
     {
        if (c == null)
        {
              c = camTexture.GetPixels32();
              H = camTexture.height;
              W = camTexture.width;
        }
  
  
  
     }
  </code></pre>
  
  <p>EDIT 2: I have separated the decode stage into two bits, firstly generating the result object then retrieving the text property of the result as shown:</p>
  
  <pre><code>if (c != null){
                  print ("Start Decode!");
                  var initResult = barcodeReader.Decode(c, W, H); 
                  print ("Got past decode!");
                  result = initResult.Text; //This line of code is generating unknown exceptions for some arcane reason
                  print ("Got past text conversion!");
              }
  </code></pre>
  
  <p>It is when the text value of the result is being retrieved that is causing the error. I still do not know how to fix it though.</p>
  
  <p>Can someone please advise me?</p>
  
  <p>Thanks</p>