microsoft / microsoft/onnxruntime-inference-examples
Pointer being freed was not allocated while building onnxruntime-objc in flutter as a Method Channel
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 414
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 14
Description
I would like to reopen this comment with some weird behaviour.
Hardware: Compiling the project on a M2 Mac Pro and testing on a real iPad Air 5th gen
Common Steps:
- Added onnxruntime-objc to pod
Experiment 1: Created a fresh project with the pod and ran this part of the code:
`import onnruntime-objc
var session: ORTSession
var env: ORTEnv
let modelPath = Bundle.main.path(
forResource: "trajectory",
ofType: "ort"
)
print(modelPath)
do {
env = try ORTEnv(loggingLevel: ORTLoggingLevel.verbose)
let options = try ORTSessionOptions()
try options.setLogSeverityLevel(ORTLoggingLevel.verbose)
try options.setIntraOpNumThreads(threadCount)
session = try ORTSession(env: env, modelPath: modelPath!, sessionOptions: options)
} catch{
print("Unable to load the model")
}
I am able to create an ort session in this experiment.
Experiment 2: Created a flutter project and communicating with the iOS module using a method channel.
Flutter part:
static const platform = MethodChannel('samples.flutter.dev/onnx');
final int result = await platform.invokeMethod('getOnnxRuntime',trajData);
Ios Part (AppDelegate.swift)
`
import onnxruntime_objc
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/onnx",
binaryMessenger: controller.binaryMessenger)
batteryChannel.setMethodCallHandler({
[weak self] (call: FlutterMethodCall, result: FlutterResult) -> Void in
guard call.method == "getOnnxRuntime" else {
result(FlutterMethodNotImplemented)
return
}
var session: ORTSession
var env: ORTEnv
let modelPath = Bundle.main.path(
forResource: "trajectory",
ofType: "ort"
)
do {
env = try ORTEnv(loggingLevel: ORTLoggingLevel.verbose)
let options = try ORTSessionOptions()
try options.setLogSeverityLevel(ORTLoggingLevel.verbose)
try options.setIntraOpNumThreads(threadCount)
// Create the ORTSession
session = try ORTSession(env: env, modelPath: modelPath!, sessionOptions: options)
print("helllooo");
} catch {
print("Failed to create ORTSession.")
}
result(10)
})
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
`
This experiment gives me an error at creating a ORTEnv:
Runner(7527,0x20084f900) malloc: *** error for object 0x281e153f8: pointer being freed was not allocated
Runner(7527,0x20084f900) malloc: *** set a breakpoint in malloc_error_break to debug
libsystem_malloc.dylibmalloc_error_break:
-> 0x1b8a73374 <+0>: pacibsp
0x1b8a73378 <+4>: stp x29, x30, [sp, #-0x10]!
0x1b8a7337c <+8>: mov x29, sp
0x1b8a73380 <+12>: nop
0x1b8a73384 <+16>: ldp x29, x30, [sp], #0x10
0x1b8a73388 <+20>: retab
`
PS: If I change the pod from onnxruntime-objc to onnxruntime-mobile-objc I get this same error while creating an ORTSession...This is very confusing...Any help would be appreciated
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two experiments on the stated M2 Mac and iPad setup, comparing the fresh iOS project with the Flutter Method Channel integration. Start in AppDelegate.swift around ORTEnv and ORTSession creation, and verify whether the malloc error occurs at ORTEnv or ORTSession for each pod. Done means the failing configuration and error location are isolated and documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flutter, ios, objective-c, swift
- Domain
- machine-learning, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100