Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crashed in construction of Ort::Env, xcode13, iPhoneX #11446

Closed
lanyuer opened this issue Apr 28, 2022 · 14 comments
Closed

crashed in construction of Ort::Env, xcode13, iPhoneX #11446

lanyuer opened this issue Apr 28, 2022 · 14 comments
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@lanyuer
Copy link

lanyuer commented Apr 28, 2022

Just when I tried this I got a crash.

std::string onnx_path = "./modnet_cpu.onnx";
Ort::Env ort_env;

crash info:
KeepDemo(5283,0x106ca4580) malloc: *** error for object 0x281dd9458: pointer being freed was not allocated KeepDemo(5283,0x106ca4580) malloc: *** set a breakpoint in malloc_error_break to debug dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib

Thanks for helping me to solve it

@edgchen1
Copy link
Contributor

edgchen1 commented May 4, 2022

Would you mind providing more details? E.g., version of ONNX runtime, full code example that reproduces the issue.

@lanyuer
Copy link
Author

lanyuer commented May 5, 2022

Would you mind providing more details? E.g., version of ONNX runtime, full code example that reproduces the issue.

Thanks.

  1. The ONNX runtime version is 1.11.
    I installed onnxruntime framework by "arch -x86_64 pod install" on my Macbook Air(M1), where the content of Podfile is like:

target 'myDemo' do
  use_frameworks!

  pod 'onnxruntime-c'
  pod 'OpenCV', '~>4.3'
end
  1. Codes in my project:

image

image

@edgchen1 edgchen1 transferred this issue from microsoft/onnxruntime-inference-examples May 5, 2022
@RandySheriffH
Copy link
Contributor

RandySheriffH commented May 11, 2022

@lanyuer: are u with IOS project or MacOS project? Further - since it is M1, is x86_64 onnxruntime a compatible version?

@lanyuer
Copy link
Author

lanyuer commented May 11, 2022

@lanyuer: are u with IOS project or MacOS project? Further - since it is M1, is x86_64 onnxruntime a compatible version?

Yes it's IOS project.

@RandySheriffH
Copy link
Contributor

@lanyuer : thanks for confirming that.
Then why consuming x86_64 onnxruntime package on M1? Are u with simulator or something? Please elaborate.

@lanyuer
Copy link
Author

lanyuer commented May 12, 2022

Then why consuming x86_64 onnxruntime package on M1?
:Sorry I forgot to fix there, but when I change it from “arch -x86_64 pod install” to “pod install", and reinstall the onnxruntime-c library, I still get the same error.

Are u with simulator or something?
:No, the application crashed when it's running on a real iPhone X.

@lanyuer
Copy link
Author

lanyuer commented May 16, 2022

threadinfo

    frame #0: 0x00000001bb44cbbc libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000001dbde3854 libsystem_pthread.dylib`pthread_kill + 208
    frame #2: 0x000000018b43f6a4 libsystem_c.dylib`abort + 124
    frame #3: 0x0000000191ec09d8 libsystem_malloc.dylib`malloc_vreport + 548
    frame #4: 0x0000000191ec0b88 libsystem_malloc.dylib`malloc_report + 60
    frame #5: 0x0000000191ea6cec libsystem_malloc.dylib`free + 284
    frame #6: 0x000000010525b554 KeepHealth`google::protobuf::RepeatedField<float>::~RepeatedField() + 60
    frame #7: 0x0000000104c3bc8c KeepHealth`onnx::TensorProto::~TensorProto() + 292
    frame #8: 0x0000000104c2ef14 KeepHealth`onnx::AttributeProto::SharedDtor() + 128
    frame #9: 0x0000000104c2ec88 KeepHealth`onnx::AttributeProto::~AttributeProto() + 56
    frame #10: 0x0000000104b9f114 KeepHealth`onnx::FunctionBodyHelper::NodeDef onnx::FunctionBodyHelper::Const<float>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, float const&) + 396
    frame #11: 0x0000000104b9d53c KeepHealth`onnx::OpSchema onnx::GetOpSchema<onnx::MeanVarianceNormalization_Onnx_ver9>() + 444
    frame #12: 0x00000001051dbf00 KeepHealth`onnx::OpSet_Onnx_ver9::ForEachSchema(std::__1::function<void (onnx::OpSchema&&)>) + 1204
    frame #13: 0x00000001051d6fe4 KeepHealth`onnx::RegisterOnnxOperatorSetSchema() + 448
    frame #14: 0x00000001051d6d48 KeepHealth`void std::__1::__call_once_proxy<std::__1::tuple<onnxruntime::Environment::Initialize(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_delete<onnxruntime::logging::LoggingManager> >, OrtThreadingOptions const*, bool)::$_4&&> >(void*) + 824
    frame #15: 0x0000000198550bbc libc++.1.dylib`std::__1::__call_once(unsigned long volatile&, void*, void (*)(void*)) + 160
    frame #16: 0x00000001051d0d80 KeepHealth`onnxruntime::Environment::Initialize(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_delete<onnxruntime::logging::LoggingManager> >, OrtThreadingOptions const*, bool) + 452
    frame #17: 0x00000001051d0b5c KeepHealth`onnxruntime::Environment::Create(std::__1::unique_ptr<onnxruntime::logging::LoggingManager, std::__1::default_delete<onnxruntime::logging::LoggingManager> >, std::__1::unique_ptr<onnxruntime::Environment, std::__1::default_delete<onnxruntime::Environment> >&, OrtThreadingOptions const*, bool) + 128
    frame #18: 0x000000010522d9f4 KeepHealth`OrtEnv::GetInstance(OrtEnv::LoggingManagerConstructionInfo const&, onnxruntime::common::Status&, OrtThreadingOptions const*) + 664
    frame #19: 0x0000000105213668 KeepHealth`OrtApis::CreateEnv(OrtLoggingLevel, char const*, OrtEnv**) + 52
  * frame #20: 0x0000000104b1c498 KeepHealth`Ort::Env::Env(this=0x000000016b2f4de0, logging_level=ORT_LOGGING_LEVEL_INFO, logid="Default") at onnxruntime_cxx_inline.h:300:16
    frame #21: 0x0000000104b1a1d4 KeepHealth`Ort::Env::Env(this=0x000000016b2f4de0, logging_level=ORT_LOGGING_LEVEL_INFO, logid="Default") at onnxruntime_cxx_inline.h:299:72
    frame #22: 0x0000000104b2b6d8 KeepHealth`-[MattingDetectorBridge initModnet](self=0x000000028308c860, _cmd="initModnet") at MattingDetectorBridge.mm:51:18
    frame #23: 0x0000000104b2cb60 KeepHealth`ViewController.modelInit(self=0x00000001067063a0) at ViewController.swift:41:33
    frame #24: 0x0000000104b2ca4c KeepHealth`ViewController.viewDidLoad(self=0x00000001067063a0) at ViewController.swift:32:14
    frame #25: 0x0000000104b2cad0 KeepHealth`@objc ViewController.viewDidLoad() at <compiler-generated>:0
    frame #26: 0x00000001831b71d4 UIKitCore`-[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 104
    frame #27: 0x00000001831b9a4c UIKitCore`-[UIViewController loadViewIfRequired] + 1020
    frame #28: 0x000000018318e480 UIKitCore`-[UIViewController view] + 28
    frame #29: 0x00000001832c77b8 UIKitCore`-[UIWindow addRootViewControllerViewIfPossible] + 176
    frame #30: 0x0000000183222714 UIKitCore`-[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 224
    frame #31: 0x00000001832b479c UIKitCore`-[UIWindow _setHidden:forced:] + 252
    frame #32: 0x00000001832ce1d0 UIKitCore`-[UIWindow _mainQueue_makeKeyAndVisible] + 52
    frame #33: 0x00000001834fa02c UIKitCore`-[UIApplication _callInitializationDelegatesWithActions:forCanvas:payload:fromOriginatingProcess:] + 3692
    frame #34: 0x00000001834e365c UIKitCore`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1176
    frame #35: 0x000000018335156c UIKitCore`-[_UISceneLifecycleMultiplexer completeApplicationLaunchWithFBSScene:transitionContext:] + 148
    frame #36: 0x00000001831b856c UIKitCore`_UIScenePerformActionsWithLifecycleActionMask + 96
    frame #37: 0x00000001832dae34 UIKitCore`__101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 188
    frame #38: 0x00000001833f01e4 UIKitCore`-[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 240
    frame #39: 0x0000000183618604 UIKitCore`-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 744
    frame #40: 0x00000001835a836c UIKitCore`-[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 336
    frame #41: 0x00000001831b92b8 UIKitCore`__186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 188
    frame #42: 0x0000000183274d54 UIKitCore`+[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:] + 812
    frame #43: 0x00000001831bb048 UIKitCore`_UISceneSettingsDiffActionPerformChangesWithTransitionContext + 248
    frame #44: 0x000000018329f58c UIKitCore`-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 356
    frame #45: 0x00000001836f5070 UIKitCore`__64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.578 + 772
    frame #46: 0x00000001831e8cf0 UIKitCore`-[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 248
    frame #47: 0x000000018322a944 UIKitCore`-[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 264
    frame #48: 0x0000000183355fd4 UIKitCore`-[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 560
    frame #49: 0x000000018329d9a8 UIKitCore`-[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 360
    frame #50: 0x0000000191e2bc50 FrontBoardServices`-[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 412
    frame #51: 0x0000000191e4df98 FrontBoardServices`__94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke.180 + 100
    frame #52: 0x0000000191e0ebdc FrontBoardServices`-[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 232
    frame #53: 0x0000000191e0ffd4 FrontBoardServices`__94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke + 312
    frame #54: 0x00000001065c9fc4 libdispatch.dylib`_dispatch_client_callout + 16
    frame #55: 0x00000001065cd4cc libdispatch.dylib`_dispatch_block_invoke_direct + 228
    frame #56: 0x0000000191e102ac FrontBoardServices`__FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 40
    frame #57: 0x0000000191e0f7c0 FrontBoardServices`-[FBSSerialQueue _targetQueue_performNextIfPossible] + 176
    frame #58: 0x0000000191e13960 FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 24
    frame #59: 0x0000000180d9beec CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame #60: 0x0000000180dac01c CoreFoundation`__CFRunLoopDoSource0 + 204
    frame #61: 0x0000000180cee214 CoreFoundation`__CFRunLoopDoSources0 + 256
    frame #62: 0x0000000180cf38e8 CoreFoundation`__CFRunLoopRun + 768
    frame #63: 0x0000000180d06c30 CoreFoundation`CFRunLoopRunSpecific + 572
    frame #64: 0x00000001a172d988 GraphicsServices`GSEventRunModal + 160
    frame #65: 0x0000000183501c50 UIKitCore`-[UIApplication _run] + 1080
    frame #66: 0x000000018329b3d0 UIKitCore`UIApplicationMain + 336
    frame #67: 0x0000000104b3002c KeepHealth`main at AppDelegate.swift:12:7
    frame #68: 0x00000001065383d0 dyld`start + 444

@RandySheriffH
Copy link
Contributor

RandySheriffH commented May 18, 2022

@lanyuer : it is likely that that the pod installed are is with arm64 onnxruntime binary, to test out, mind try this?
https://github.com/microsoft/onnxruntime/releases/download/v1.11.1/onnxruntime-osx-arm64-1.11.1.tgz
Or you could also build from source by:
image

@lanyuer
Copy link
Author

lanyuer commented May 20, 2022

@lanyuer : it is likely that that the pod installed are is with arm64 onnxruntime binary, to test out, mind try this?
https://github.com/microsoft/onnxruntime/releases/download/v1.11.1/onnxruntime-osx-arm64-1.11.1.tgz

It's not worked. "xxx.xcodeproj Building for iOS, but the linked library 'libonnxruntime.1.11.1.dylib' was built for macOS."

I'll try to build from source later.

@edgchen1
Copy link
Contributor

edgchen1 commented Jun 7, 2022

Any luck building from source?
We tried running an app on an iOS device using the 1.11 pod and were unable to reproduce the issue. But it was an iPhone 12 mini.

@sophies927 sophies927 added api issues related to all other APIs: C, C++, Python, etc. platform:mobile issues related to ONNX Runtime mobile; typically submitted using template and removed platform:macOS api issues related to all other APIs: C, C++, Python, etc. labels Aug 12, 2022
@skottmckay
Copy link
Contributor

Closing as no response from user.

@joe-zxh
Copy link

joe-zxh commented Apr 28, 2023

same problem here.

If I remove the opencv, it works fine. Is there any conflict in opencv and onnx runtime? How to solve it?

@clydebailey
Copy link

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:

  1. 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

@edgchen1
Copy link
Contributor

would it be possible to get a stacktrace?

you can try to build the pods from source:
https://onnxruntime.ai/docs/build/custom.html#ios

try using config "RelWithDebInfo". "Debug" will result in a binary that is too large for CocoaPods to handle.

build_and_assemble_ios_pods.py --build-ios-framework-arg=--config=RelWithDebInfo ...
https://github.com/microsoft/onnxruntime/blob/main/tools/ci_build/github/apple/build_and_assemble_ios_pods.py

could you provide a complete (and hopefully minimal) example to reproduce the issue? I don't have experience with Flutter - if that's required, any instructions to get it running would be useful.

does your project also use OpenCV? seems to be a theme in the other comments.

@edgchen1 edgchen1 reopened this Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

7 participants