dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

App crash when initialize a delegate class from native library binding #13142

Closed gnibloop closed 1 year ago

gnibloop commented 1 year ago

Description

I am using Visual studio 2022 building a .net 7 maui project (migrating from Xamarin). I tried to Bind a native library (libWeChatSDK) successfully. (Can call methods or get properties without problem). However when I new its delegate class cause the system instant crash (On physical device, never test on simulator coz it requires installing wechat on physical device).

The Crash point is at code line:

 _wechatDelegate = new Platforms.iOS.IosWechatDelegate();

and I can check the generated code as below:

    [Protocol()]
    [Register("WXApiDelegate", true)]
    public unsafe partial class WXApiDelegate : NSObject, IWXApiDelegate {
        [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
        static readonly NativeHandle class_ptr = Class.GetHandle ("WXApiDelegate");
        public override NativeHandle ClassHandle { get { return class_ptr; } }
        [BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
        [EditorBrowsable (EditorBrowsableState.Advanced)]
        [Export ("init")]
        public WXApiDelegate () : base (NSObjectFlag.Empty)
        {
            IsDirectBinding = GetType ().Assembly == global::ApiDefinition.Messaging.this_assembly;
            if (IsDirectBinding) {
                InitializeHandle (global::ApiDefinition.Messaging.IntPtr_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("init")), "init");
            } else {
                InitializeHandle (global::ApiDefinition.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, global::ObjCRuntime.Selector.GetHandle ("init")), "init");
            }
        }

Steps to Reproduce

1 Create a maui app project 2 Create binding libraray project for Ios 3rd praty SDK (libWechatSDK) 3, put a line

var wechatDelegate = new Platforms.iOS.IosWechatDelegate();" in OnApplicedLaunched or anywhere else inside AppDelegate()

4, Run at physical device (simulator will crash as well) will instantly crash when reach the point above.

Link to public reproduction project repository

none

Version with bug

6.0.312

Last version that worked well

6.0.312

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

NO

Relevant log output

================================================================
    Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
    Native stacktrace:
=================================================================
    0x10292d464 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x102918560 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1028fcadc - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1dbc6cd48 - /usr/lib/system/libsystem_platform.dylib : <redacted>
    0x1026485dc - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/Ap
p39milesPos : _ZN16XamarinCallState3selEv
    0x10293c5c8 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x10293b374 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x102930d50 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x10292e990 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x1028ff998 - /private/var/containers/Bundle/Application/90BFFBA2
The app has been terminated.
-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x10284e990 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x102852030 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x10296b77c - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
    0x10296e608 - /private/var/containers/Bundle/Application/90BFFBA2-0BED-4CE8-AD69-296926654ED5/App39milesPos.app/App39milesPos : _ZNK3icu6number23NumberFormatterSettingsINS0_
The app has been terminated.
PureWeen commented 1 year ago

This issue was moved to xamarin/xamarin-macios#17474