Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

App crashes on Release Mode for iOS #95

Open
sasan-soroush opened this issue Dec 3, 2022 · 1 comment
Open

App crashes on Release Mode for iOS #95

sasan-soroush opened this issue Dec 3, 2022 · 1 comment

Comments

@sasan-soroush
Copy link

I know there is another issue related to this crash
But the solution to that issue is to set the optimization level to none on the Release mode, and that is not the option for our team, since we want to keep optimizing our Production App,

Is there another solution, can you provide an updated version of the predict method that doesn't cause this crash?

@sasan-soroush
Copy link
Author

sasan-soroush commented Dec 3, 2022

This code works for me: just change it inside ImagePredictor.swift -> predict method
instead of

guard let outputs = module.predict(image: UnsafeMutableRawPointer(&tensorBuffer)) else {
    throw PredictorError.invalidInputTensor
}

Use

var outputs = [NSNumber]()
tensorBuffer.withUnsafeMutableBufferPointer { ptr in
   if let baseAddress = ptr.baseAddress, let _outputs = module.predict(image: &(baseAddress.pointee)) {
       outputs = _outputs
   }
}
guard !outputs.isEmpty else {
    throw PredictorError.invalidInputTensor
}

But I won't close this issue yet, in case there is a better way.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant