UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 63 and 66 - (Instafilter project) Crystallize filter causes crash in Xcode 11.4

Forums > 100 Days of SwiftUI

When following the tutorial for adding the Core Image filter Crystallize, the app crashes when an attempt is made to use this filter. All the other filter selections work fine. I tried several different methods as explained in the tutorials but none of them were successful. It appears to be a bug in Xcode 11.4.

3      

I'm having the same issue. XCode 11.4.1.

3      

Interesting... I've found it fixed for me on Xcode 11.4. But perhaps I've modified the code so much that it suddenly started working.

The problem stems from the "modern/swifty" API CoreImage.CIFilterBuiltins to pass the input values to the filter (image and filter parameters) which was not correctly implemented for all filters (atleast this was the experience for me with Xcode < 11.4). I used the old API everywhere to make it work.

I used setValue(_, forKey:) everywhere.

currentFilter.setValue(beginImage, forKey: kCIInputImageKey)

and

if hasIntensity { currentFilter.setValue(filterIntensity, forKey: kCIInputIntensityKey) }
if hasRadius { currentFilter.setValue(filterRadius, forKey: kCIInputRadiusKey) }
if hasScale { currentFilter.setValue(filterScale, forKey: kCIInputScaleKey) }

See find my complete ContentView.swift here

3      

I tried copying in your code into my ContentView and it hits me with 3 errors related to your else {} statement inside LoadImage. It offered 3 fixes which I implemented resulting in the following code:

func loadImage() {
        guard let inputImage = inputImage else { return }

        let beginImage : CIImage
        if let ciImage = inputImage.ciImage {
            beginImage = ciImage
        }
        else {
            beginImage = CIImage(cgImage: inputImage.cgImage!).oriented(CGImagePropertyOrientation(rawValue: UInt32(inputImage.imageOrientation.rawValue))!)
        }

However, this didn't seem to make any difference with Crystallize causing a crash. For what it's worth, I also downloaded Paul's project files from git and his code also crashes with the same file error.

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

That is reported on this line in applyProcessing()

guard let outputImage = currentFilter.outputImage else { return }

And the terminal reports this when pressing the Select Filter button that triggers the ActionSheet:

2020-05-26 15:56:10.071754-0700 Instafilter[6090:271140] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "<NSLayoutConstraint:0x600002f4b890 UIView:0x7fb791729150.width == - 16 (active)>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x600002f4b890 UIView:0x7fb791729150.width == - 16 (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

This error reporting is a bit beyond my knowledge, especially since I am not familiar with UIKit.

3      

Quick update...

Since I'm working on the Accessibility project now, I am testing on a real device for the first time.

I tested my Instafilter code on my iPhone 6s and the crystallize filter will now run properly!

However, I've developed a secondary problem with my pictures (some, not all) will appear upside down after loading, but I assume that's more wonkiness with how SwiftUI deals with UI/CG/CI images...

3      

Hi Zoyd

I went again through my code and aligned it with Pauls version, starting with his version and adding my enhancements again.

My enhancements are mainly around the "sluggish performance" and the image orientation. When running it in the simulator, it always crashed... but it works on my device. So probably the only thing I properly remember was that it finally started working on the device. The simulator implementation of crystallize is still broken.

But as you found this too, you are now at the orientation issue. See my my code here. It works for me... (at least since Xcode 11.4)

regards

Philipp

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.