I'm developing a Flutter app which makes use of the Digital Ink Recognition of ML Kit to recognize handwriting.
I have the following code to perform the recognition on iOS (swift code).
let ink = Ink.init(strokes: mlStrokes)
let identifier = DigitalInkRecognitionModelIdentifier(forLanguageTag: languageTag)
if identifier == nil {
flutterResult(FlutterError(code: "ERROR", message: "No model for language tag found or the language tag could not be parsed", details: nil))
}
let model = DigitalInkRecognitionModel.init(modelIdentifier: identifier!)
// Get a recognizer for the given language
let options: DigitalInkRecognizerOptions = DigitalInkRecognizerOptions.init(model: model)
digitalInkRecognizer = DigitalInkRecognizer.digitalInkRecognizer(options: options)
digitalInkRecognizer.recognize(
ink: ink,
completion: {
(result: DigitalInkRecognitionResult?, error: Error?) in
if let result = result {
var flutterCandidates : [[String: Any?]] = []
for candidate in result.candidates {
flutterCandidates.append(
["text" : candidate.text, "score" : candidate.score]
)
}
// Return recognised candidates to Flutter.
self.flutterResult(flutterCandidates)
} else {
self.flutterResult(FlutterError(code: "ERROR", message: "Unable to recognize handwriting", details: error))
}
})
I'm recognizing a single letter at a time.
This works well for some time, the correct letter is returned in the completion callback and then send back to my Flutter app, but after the method is called a few times (~20), the following error is thrown in the console and my app crashes.
I1025 10:03:01.607888 1 lstm_recognizer.cc:77] Loaded tflite model.
2021-10-25 10:03:01.621992+0200 Runner[796:125890] Unsupported value: Error Domain=com.google.mlkit Code=13 "Unable to initialize recognizer: generic::internal: Unable to mmap file descriptor (Cannot allocate memory). (research/handwriting/util/mmap_data.cc:49)" UserInfo={NSLocalizedDescription=Unable to initialize recognizer: generic::internal: Unable to mmap file descriptor (Cannot allocate memory). (research/handwriting/util/mmap_data.cc:49)} of type NSError
2021-10-25 10:03:01.623350+0200 Runner[796:125890] *** Assertion failure in -[FlutterStandardWriter writeValue:], FlutterStandardCodec.mm:334
2021-10-25 10:03:01.632824+0200 Runner[796:125890] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unsupported value for standard codec'
*** First throw call stack:
(0x20ff2e180 0x20f1069f8 0x20fe4788c 0x21090bb38 0x1034b8138 0x1034b8898 0x1034b5890 0x100c4f0f4 0x100c522fc 0x100c523a8 0x1052536f4 0x105254c78 0x1052626fc 0x20febfb20 0x20febaa58 0x20feb9fb4 0x2120bb79c 0x23c197c38 0x100c4f464 0x20f97d8e0)
libc++abi.dylib: terminating with uncaught exception of type NSException
The error seems linked to a memory issue (Unsupported value: Error Domain=com.google.mlkit Code=13 "Unable to initialize recognizer: generic::internal: Unable to mmap file descriptor (Cannot allocate memory), but I don't find the reason.
Do I have to release something after the digitalInkRecognizer.recognize() method is called? I can't find anything related to this in the documentation.
Thanks in advance for any idea.
I found that the issue was linked to the lifecycle management of the ModelManager and recognizer which I was recreating each time I was performing the digital ink recognition.
After changing this behaviour and keeping a reference to them once created, the issue was solved.
This example was helpful to understand how to work with the ModelManager (see implementation of the StrokeManager).
Related
Currently getting the following runtime exception
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Animator <UIViewPropertyAnimator(0x600003f24200) [stopped] interruptible> is already stopped!'
Because of the following line of code
// other code up here that modifies offsetAnimator
...
// stop any current running animations on offset
if let offsetAnimator = offsetAnimator {
offsetAnimator.stopAnimation(false) // this line is where the exception gets raised
offsetAnimator.finishAnimation(at: .end)
}
What is perplexing, however, is why this error is NOT readily reproducible
// doing this doesn't always result in an error
if let offsetAnimator = offsetAnimator {
offsetAnimator.stopAnimation(false)
offsetAnimator.finishAnimation(at: .end)
offsetAnimator.stopAnimation(false)
offsetAnimator.finishAnimation(at: .end)
}
What on earth is happening? Can someone explain to me why this error is occurring?
Why does it seem to only happen sporadically? Shouldn't calling .stop twice always trigger it?
I want to send a message through my app. I call the following method on click
#IBAction func sendMessage(_ sender: Any) {
if (MFMessageComposeViewController.canSendText()) {
let composeVC = MFMessageComposeViewController()
composeVC.messageComposeDelegate = self
// Configure the fields of the interface.
composeVC.recipients = ["4085551212"]
composeVC.body = "Hello from California!"
// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)
}
}
The problem is if I run the app on device, it crashes at MFMessageComposeViewController initialisation i.e.
let composeVC = MFMessageComposeViewController()
If I run the app in simulator, it crashes on presentation i.e.
self.present(composeVC, animated: true, completion: nil)
Error log when I run the app on device
2018-01-29 12:03:57.826816+0530 EWS[2495:806400] *** Assertion failure in -[UICGColor encodeWithCoder:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3698.33.7/UIColor.m:1722
2018-01-29 12:03:57.827522+0530 EWS[2495:806400] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.'
*** First throw call stack:
(0x183702364 0x182948528 0x183702238 0x18409d7f4 0x18d08fffc 0x1840574dc 0x18405e8d8 0x18d4ebf20 0x18d4eb74c 0x18d4e7044 0x1835d03c0 0x18d4e6d44 0x18d7f16fc 0x18d60bd18 0x18d60b94c 0x19aee4534 0x19aecbff4 0x19aecc314 0x1984ce830 0x101159ec0 0x101158888 0x1011584b4 0x1011589c0 0x18cc186b4 0x18cc18634 0x18cc031dc 0x18cc17f28 0x18cc17a48 0x18cc12f60 0x18cbe3f64 0x18d53931c 0x18d53b8a8 0x18d5347c0 0x1836aa97c 0x1836aa8fc 0x1836aa184 0x1836a7d5c 0x1835c7e58 0x185474f84 0x18cc4767c 0x101157170 0x1830e456c)
libc++abi.dylib: terminating with uncaught exception of type NSException
Error log when I run the app on simulator (without checking if(MFMessageComposeViewController.canSendText()))
2018-01-29 12:07:49.395714+0530 EWS[3533:67163] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <EWS.BlockVC: 0x7f899c61db10>.'
*** First throw call stack:
Any help would be appreciated.
Okay,
When you run it in iPhone : The crash log clearly states that "Only RGBA or White color spaces are supported in this situation." So by hint I would say you are assigning color somewhere, (Some Global tint, navigation bar tint) , which doesn't apply to a MFMessageComposeViewController, hence its crashing.
When you run it in the simulator :
if (MFMessageComposeViewController.canSendText()), this line will prevent it from initialising the MFMessageComposeViewController, in the simulator as it cant send text, hence when you try to present it, its not yet initialised and crashing.
On a second thought, as per your code : self.presentViewController(composeVC, animated: true, completion: nil), this line should not even be called while running in the simulator as this line is inside the if statement, which wont get through.
Also change the tint color or any while initialising the controller, and tell me what the results are.
I am using Google PlaceAutoComplete method to get suggestions of the Addess that is entered in textField.
func placeAutocomplete(text:String) {
let placesClient = GMSPlacesClient()
let filter = GMSAutocompleteFilter()
filter.type = .Address
placesClient.autocompleteQuery("New Delhi", bounds: nil, filter: nil) { (results, error) in
guard error == nil else {
print("Autocomplete error \(error)")
return
}
self.addressArray.removeAll()
for result in results! {
self.addressArray.append(result.attributedFullText.string)
print("Result \(result.attributedFullText.string) with placeID \(result.placeID)")
}
}
}
When i call this method. It crashes, say the Following error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary boolValue]: unrecognized selector sent to instance 0x7fe338f01e40'
I have tried to found using exception breakpoint but doesn't work.
Can any have idea, where i am wrong?
I have resolved the issue by correcting in the plist for "allow arbitrary loads" in App Transport security Settings. I was typed it true but its type was set string instead for Boolean
Somewhere a NSDictionary is being passed to the code where it is expecting a something that can be interpreted as a boolean such as an NSString or NSNumber. I don't see anything like that in the code you provided. If exception breakpoints aren't working I would try adding normal breakpoints somewhere and stepping over code until it crashes. You could also try removing certain sections and code and seeing if the crash is still happening, this will let you narrow down what portion of your code is to blame.
I'm scratching my head over this one, I thought the whole point of checking for nil was to ensure unsafe variables were ignored at run-time allowing the app to not crash.
I have tried to check the key returned from the server for nil, and also tried optional chaining to test for nil, neither are working and I still get the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "avatar" has no data. Call fetchIfNeeded before getting its value.'
I understand this means that no data was found for the avatar key, but due to the tests I am running I'm confused why this error is even being raised
for var i = 0; i < recipients.count; i++
{
if let u = recipients[i] as PFUser!
{
if u.valueForKey("avatar") != nil
{
println(i)
}
}
}
Conversely, I tried to optional chain the result of the image:
if let image: UIImage = UIImage(data: (u["avatar"]!.getData() as NSData?)!) {}
Both times the application will crash throwing the exception stated above. My stack trace shows nothing else which is of use, however the println statement will print 0, 1 and then crash on element 2 (where the collection size is 4 so I am not out of bounds).
Any ideas on how I can fix this?
Can anyone shed any light on the reason for the following failure:
*** Assertion failure in -[Alien rotation],
/Users/admininstrator/Documents/moonweed/Star Pilot v4.0/Star Pilot
#1/Libraries/cocos2d/CCNode.m:258
2014-11-06 23:28:51.680 Star Pilot #1[2141:987748] *** Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'CCNode#rotation. rotationalSkewX
!= rotationalSkewY. Don't know which one to return'
Looking at the Cocos2d source, I can see that the Assertion is coming from CCNode.m, from the method below:
-(float) rotation
{
CCPhysicsBody *body = GetBodyIfRunning(self);
if(body){
return -CC_RADIANS_TO_DEGREES(body.absoluteRadians) +
NodeToPhysicsRotation(self.parent);
} else {
NSAssert( _rotationalSkewX == _rotationalSkewY, #"CCNode#rotation. rotationalSkewX != rotationalSkewY. Don't know which one to return");
return _rotationalSkewX;
}
}
The code runs fine on all simulators, using Xcode 6.1. But on my iPhone 5, it crashes. I'm struggling to figure why? I'm currently using Cocos2d V3.x.