Home Ask Login Register

Developers Planet

Your answer is one click away!

Roi Mulia February 2016

GPUImageView stop responding to "Filter Change" after two times

I'm probably missing something. I'm trying to change filter to my GPUImageView.It's actually working the first two times(sometimes only one time), and than stop responding to changes. I couldn't find a way to remove the target from my GPUImageView.


for x in filterOperations
        let f = filterOperations[randomIntInRange].filter
        let media = GPUImagePicture(image: self.largeImage)
        media?.addTarget(f as! GPUImageInput)

Any suggestions? * Processing still image from my library


Updated Code


var g_View: GPUImageView!
var media = GPUImagePicture()

override func viewDidLoad() {
    media = GPUImagePicture(image: largeImage)

func changeFilter(filterIndex : Int)
    let f = returnFilter(indexPath.row) //i.e GPUImageSepiaFilter()
    media.addTarget(f as! GPUImageInput)

    //second Part
    let sema = dispatch_semaphore_create(0)

     dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER)
     let img =       f.imageFromCurrentFramebufferWithOrientation(img.imageOrientation)
     if img != nil
     //Useable - update UI

        //  Something Went wrong




Brad Larson February 2016

My primary suggestion would be to not create a new GPUImagePicture every time you want to change the filter or its options that you're applying to an image. This is an expensive operation, because it requires a pass through Core Graphics and a texture upload to the GPU.

Also, since you're not maintaining a reference to your GPUImagePicture beyond the above code, it is being deallocated as soon as you pass out of scope. That tears down the render chain and will lead to a black image or even crashes. processImage() is an asynchronous operation, so it may still be in action at the time you exit your above scope.

Instead, create and maintain a reference to a single GPUImagePicture for your image, swap out filters (or change the options for existing filters) on that, and target the result to your GPUImageView. This will be much faster, churn less memory, and won't leave you open to premature deallocation.

Post Status

Asked in February 2016
Viewed 1,037 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life