Question

I wrote some code which creates a filter and can be controlled via a UISlider. But if I slide the UISlider, the app crashes.

My code:

.m file:

- (void) viewDidLoad {

    [_sliderBrightness addTarget:self action:@selector(brightnessFilter) forControlEvents:UIControlEventValueChanged];
    _sliderBrightness.minimumValue = -1.0;
    _sliderBrightness.maximumValue = 1.0;
    _sliderBrightness.value = 0.0;
}

- (IBAction)sliderBrightness:(UISlider *)sender {

    CGFloat midpoint = [(UISlider *)sender value];
    [(GPUImageBrightnessFilter *)brightFilter setBrightness:midpoint - 0.1];
    [(GPUImageBrightnessFilter *)brightFilter setBrightness:midpoint + 0.1];

    [sourcePicture processImage];
}


- (void) brightnessFilter {

    UIImage *inputImage = _imgView.image;

    sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
    brightFilter = [[GPUImageBrightnessFilter alloc] init];

    GPUImageView *imgView2 = (GPUImageView *)self.view;

    [brightFilter useNextFrameForImageCapture];
    [sourcePicture addTarget:brightFilter];

    [sourcePicture processImage];

    UIImage* outputImage = [brightFilter imageFromCurrentFramebufferWithOrientation:0];
    [_imgView setImage:outputImage];
}

Error:

GPUImageFramebuffer.m:

}
        else
        {
            [self activateFramebuffer];
            rawImagePixels = (GLubyte *)malloc(totalBytesForImage);
            glReadPixels(0, 0, (int)_size.width, (int)_size.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels);
            dataProvider = CGDataProviderCreateWithData(NULL, rawImagePixels, totalBytesForImage, dataProviderReleaseCallback);
            [self unlock]; // Don't need to keep this around anymore
        }

In this line of code:

    [self activateFramebuffer];

Error message:

Thread 1: EXC_BAD_ACCESS (code=EXC_1386_GPFLT)

Console:

self = (GPUImageFramebuffer *const) 0x10a0a6960
rawImagePixels = (GLubyte *) 0x190
dataProvider = (CGDataProviderRef) 0x0
renderTarget = (CVPixelBufferRef) 0x8

Maybe the dataProvider causes the crash but I don't really know because I'm new in developing iOS apps.

Was it helpful?

Solution

This obviously isn't going to work (and shouldn't even compile) because GPUImageBrightnessFilter has no -setTopFocusLevel: or -setBottomFocusLevel: method. You copied this from my sample application without changing these methods to the one appropriate to a brightness filter (which is the brightness property).

It's also rather confusing (and potentially problematic) to have both a brightnessFilter instance variable and -brightnessFilter method. You probably want to rename the former to make it clear that's where you're performing your initial setup of the filter and source image. You'll also need to call that in your view controller's setup (after your Nib is loaded).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top