Skip to content

Commit 8a9ad24

Browse files
author
Daniel Llewellyn
committed
Update ios/Classes/TflitePlugin.mm
* Don't shadow the `options` variable with a duplicate name in the CoreML code * Ensure we clean up the coreml delegate correctly Signed-off-by: Daniel Llewellyn <[email protected]>
1 parent d578c64 commit 8a9ad24

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ios/Classes/TflitePlugin.mm

+10-4
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
119119
TfLiteInterpreter *interpreter = nullptr;
120120
TfLiteModel *model = nullptr;
121121
TfLiteDelegate *delegate = nullptr;
122+
bool isCoreMLDelegate = false;
122123
#else
123124
std::unique_ptr<tflite::FlatBufferModel> model;
124125
std::unique_ptr<tflite::Interpreter> interpreter;
@@ -161,12 +162,14 @@ static void LoadLabels(NSString* labels_path,
161162
}
162163
options = TfLiteInterpreterOptionsCreate();
163164
TfLiteInterpreterOptionsSetNumThreads(options, num_threads);
164-
165+
165166
bool useGpuDelegate = [args[@"useGpuDelegate"] boolValue];
166167
bool useCoreMLDelegate = [args[@"useCoreMLDelegate"] boolValue];
167168
if (useCoreMLDelegate) {
168-
TfLiteCoreMlDelegateOptions options = {};
169-
delegate = TfLiteCoreMlDelegateCreate(&options);
169+
delegate = TfLiteCoreMlDelegateCreate(nullptr);
170+
if (delegate != NULL) {
171+
isCoreMLDelegate = true;
172+
}
170173
}
171174
if (delegate == NULL && useGpuDelegate) {
172175
delegate = TFLGpuDelegateCreate(nullptr);
@@ -1496,8 +1499,11 @@ void runPoseNetOnFrame(NSDictionary* args, FlutterResult result) {
14961499
void close() {
14971500
#ifdef TFLITE2
14981501
interpreter = nullptr;
1499-
if (delegate != nullptr)
1502+
if (isCoreMLDelegate && delegate != nullptr) {
1503+
TfLiteCoreMlDelegateDelete(delegate);
1504+
} else if (delegate != nullptr) {
15001505
TFLGpuDelegateDelete(delegate);
1506+
}
15011507
delegate = nullptr;
15021508
#else
15031509
interpreter.release();

0 commit comments

Comments
 (0)