Got a crash when using GPUImageFilter

半世苍凉 提交于 2019-12-01 12:33:03

问题


I started from Brad Larson's Tutorial on Github.Here when i added these code into my project

- (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:self.view.bounds];

[self.view addSubview:filteredVideoView];

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

[videoCamera startCameraCapture];
}

and i got a crash in the methods - (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString;

With log outputted as follow:

 013-08-04 17:17:37.567 ViewPack[36088:907] Failed to load vertex shader
2013-08-04 17:17:37.570 ViewPack[36088:907] Failed to compile fragment shader
2013-08-04 17:17:37.572 ViewPack[36088:907] Program link log: ERROR: OpenGL ES 2.0        requires exactly one vertex and one fragment shader to validly link.
2013-08-04 17:17:37.573 ViewPack[36088:907] Fragment shader compile log: (null)
2013-08-04 17:17:37.574 ViewPack[36088:907] Vertex shader compile log: (null)
2013-08-04 17:17:37.576 ViewPack[36088:907] *** Assertion failure in -[GPUImageFilter   initWithVertexShaderFromString:fragmentShaderFromString:],  /Users/dachang/Desktop/Files/Libs/GPUImage-master/framework/Source/GPUImageFilter.m:97

I think i had correctly add GPIImage into my project, cause i do can import all those headers. I don't know what ' OpenGL ES 2.0 requires exactly one vertex and one fragment shader to validly link.' means.(and I cannot find CustomShader.fsh file)

Can anybody please help..thanks a lot..


回答1:


The above code tries to create a filter from a custom fragment shader file (in this case, CustomShader.fsh). For this to work, you need to have a file by that name in your project, and need to make sure that it is in the copying resources build phase for your project, not the compiling sources build phase. It also must be a valid fragment shader of the style expected by the project. The MultiViewFilterExample has one of these.

I should note that this is only necessary if you want to create your own custom fragment shader for a filter. As an alternative, you can use one of the 100+ other filters that come with the framework, and avoid this process.



来源:https://stackoverflow.com/questions/18041627/got-a-crash-when-using-gpuimagefilter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!