-processImage
is asynchronous. It won't run to completion when you call it, so you need to maintain the filter structure until it finishes processing.
This means that you can't call -removeTarget:
right afterwards, and also means that you'll need for your sourcePicture
instance to hang around as an instance variable until the processing is completed. Otherwise, it will be deallocated at the end of this method and will tear down its outputs as a result.
You want to set up your filter chain and run -processImage
when everything's configured properly. You need to maintain the source picture for as long as you need the filtered result.