由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'过滤器着色器链接失败'

时间:2014-05-28 11:29:37

标签: ios objective-c gpuimage gpuimagestillcamera

我需要显示实时相机输入。我使用了GPUImage,当我执行代码时我得到了这个错误。我提到了一些文档,我在viewDidLoad中编写了代码。当我打开应用程序时,它会崩溃。

 - (void)viewDidLoad
    {
        [super viewDidLoad];
    GPUImageVideoCamera *videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

    GPUImageFilter *customFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"CustomShader"];
    GPUImageView *filteredVideoView = [[GPUImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height)];

    // Add the view somewhere so it's visible

    [videoCamera addTarget:customFilter];
    [customFilter addTarget:filteredVideoView];

    [videoCamera startCameraCapture];

    }

日志:

Failed to load vertex shader
  Failed to compile fragment shader
 Program link log: ERROR: OpenGL ES 2.0 requires exactly one vertex and one fragment shader to validly link.
 Fragment shader compile log: (null)
 Vertex shader compile log: (null)
  *** Assertion failure in -[GPUImageFilter initWithVertexShaderFromString:fragmentShaderFromString:], /Users/ranganathagv/Projects/MobileApp/test/iOS/View/28May_GPU/BradLarson-GPUImage-f67cbd9/framework/Source/GPUImageFilter.m:76
  *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Filter shader link failed'

1 个答案:

答案 0 :(得分:1)

确保着色器已添加到Copy Bundle Resources构建阶段。默认情况下,Xcode会尝试将它们编译为源代码文件,而不是像应该的那样将它们包含在应用程序包中。