I have a simple Metal CIWarpKernel
:
float2 MyWarp(destination dest, float offset)
{
return float2(dest.coord().x + offset, dest.coord().y);
}
and:
class MyWarpFilter : CIFilter
{
var inputImage: CIImage?
var inputOffset: Float = 100.0
static var kernel: CIWarpKernel =
{ () -> CIWarpKernel in
let url = Bundle.main.url(forResource: "MyWarp", withExtension: "ci.metallib")!
let data = try! Data(contentsOf: url)
return try! CIWarpKernel(functionName: "MyWarp", fromMetalLibraryData: data) <== ERROR
}()
override var outputImage : CIImage?
{
get
{
guard let input = inputImage else { return nil }
let roiCallback: CIKernelROICallback =
{ _, rect -> CGRect in
return CGRect(x: rect.minX, y: rect.minY, width: input.extent.width, height: input.extent.height)
}
let arguments: [Any] = [inputOffset]
return MyWarpFilter.kernel.apply(extent: input.extent,
roiCallback: roiCallback,
image: input, arguments: arguments)
}
}
}
When I run this, I get the following run-time error (at line indicated above with <== ERROR
):
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Foundation._GenericObjCError.nilError
If I remove the second MyWarp()
parameter, run the filter with arguments: []
and have a hard-coded offset, there's no error (and the filter translates the image by offset).
What am I doing wrong with passing arguments to the CIWarpKernel
?