       if let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
         let width = CVPixelBufferGetWidth(pixelBuffer)
         let height = CVPixelBufferGetHeight(pixelBuffer)
-        var texture:CVMetalTexture? = nil
-        let status = CVMetalTextureCacheCreateTextureFromImage(nil, textureCache, pixelBuffer, nil, MTLPixelFormat.r8Unorm, width, height, 0, &texture)
-        if let texture = texture, status == kCVReturnSuccess {
+        var metalTexture:CVMetalTexture? = nil
+        let status = CVMetalTextureCacheCreateTextureFromImage(nil, textureCache, pixelBuffer, nil, MTLPixelFormat.r8Unorm, width, height, 0, &metalTexture)
+        if let metalTexture = metalTexture, status == kCVReturnSuccess,
+           let _ = CVMetalTextureGetTexture(metalTexture) {
           //print("capture", width, height, texture)
-          //render(metalTexture:texture)
         } else {
           print("capture failed")
         }

    super.viewDidLoad()
    
    if let mtkView = self.view as? MTKView {
        mtkView.device = MTLCreateSystemDefaultDevice()
        renderer = VSRenderer(view: mtkView)
        renderer?.mtkView(mtkView, drawableSizeWillChange: mtkView.drawableSize)
        mtkView.delegate = renderer

    CVMetalTextureCacheCreate(nil, nil, VideoSessionController.device, nil, &cache)
    return cache!
  }()
  
  // Debug only for Metal
  let vertexData:[Float] = [ -1.0, -1.0,  0.0, 1.0,
