Question

If I debug my app. The app crashes in this line of code and I get this warning:

Warning:

Local declaration of 'imgView' hides instance variable

Line of code:

[brightnessFilter forceProcessingAtSize:imgView.sizeInPixels]; 

Block of code:

- (IBAction)sliderBrightness:(id)sender {

    UIImage *inputImage = imgView.image;

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

    GPUImageView *imgView = (GPUImageView *)self.view;
    [brightnessFilter forceProcessingAtSize:imgView.sizeInPixels]; 

    [sourcePicture addTarget:brightnessFilter];
    [brightnessFilter addTarget:imgView];

    [sourcePicture processImage];
}

Can someone help me to solve the problem?

Était-ce utile?

La solution

Andrey gave you the basics. To be very specific.

Here is your current code:

- (IBAction)sliderBrightness:(id)sender {

    UIImage *inputImage = imgView.image; // <--- This line refers to an instance var

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

    GPUImageView *imgView = (GPUImageView *)self.view; <--- This line defines a local
    [brightnessFilter forceProcessingAtSize:imgView.sizeInPixels]; 

    [sourcePicture addTarget:brightnessFilter];
    [brightnessFilter addTarget:imgView];

    [sourcePicture processImage];
}

Look at the to comments I added that start with " <--- This line". The first one marks your reference to an instance variable imgView.

The second comment marks a place where you define a different, local variable with the same name, imgView.

If you intend to use a different local variable, change that name to something else, like

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

If you intend to change the instance variable, then make it an assignment, and get rid of the variable declaration:

   imgView = (GPUImageView *)self.view;

I'm guessing that you want the second case, where you change the contents of the instance variable, but I'm not sure. It's your code.

Autres conseils

Replace this code:

GPUImageView *imgView = (GPUImageView *)self.view;
[brightnessFilter forceProcessingAtSize:imgView.sizeInPixels]; 

[sourcePicture addTarget:brightnessFilter];
[brightnessFilter addTarget:imgView];

with this code:

GPUImageView *imgView2 = (GPUImageView *)self.view;
[brightnessFilter forceProcessingAtSize:imgView2.sizeInPixels]; 

[sourcePicture addTarget:brightnessFilter];
[brightnessFilter addTarget:imgView2];

You have 2 variables with the name imgView which is giving you the warning, but there is no reason for this to cause the crash. The crash is because of some other reason which is outside of the code you have provided.

You have declared two variables(Local and Instance) with name imgView.Change the local variable instance of GPUImageView from imgView to some other name say gpuimgView

- (IBAction)sliderBrightness:(id)sender {

    UIImage *inputImage = imgView.image;

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

    GPUImageView *gpuimgView = (GPUImageView *)self.view;//changed to gpuimgView
    [brightnessFilter forceProcessingAtSize:gpuimgView.sizeInPixels]; 

    [sourcePicture addTarget:brightnessFilter];
    [brightnessFilter addTarget:gpuimgView];

    [sourcePicture processImage];
}

Hope it will helps you....

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top