SpatialAwareness example scenes doesn't work

After updating to 1.5.0 our spatial awareness all went green, and after trying to debug, we decided to try and implement using MRTK spatial awareness (as this wasn't available when we initially set up the project).
But just building the sample scene doesn't work. A bunch of errors (seems like the meshparent gets destroyed), and initialization order (permission request before OnEnable) also gives errors.
Also, there's UI in the scene but he MRTK profile doesn't include any Input Profile.

After fixing all of these errors in the MaigcLeapSpatialMeshObserver, we're still getting this last error, (and the mesh is still not showing up);

Unity Editor version:
2022.2.6
ML2 OS version:
1.2.0
MLSDK version:
1.6.0

2023-05-01 12:13:25.503 28819 28848 Error Unity NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: UnityEngine.XR.MagicLeap.MLAutoAPISingleton`1[[UnityEngine.XR.MagicLeap.MLPermissions, MagicLeap.SDK, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::OnPerceptionShutdown
2023-05-01 12:13:25.503 28819 28848 Error Unity   at UnityEngine.XR.MagicLeap.MLAutoAPISingleton`1[T].Initialize () [0x0005b] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\Common\MLAutoAPISingleton.cs:56 
2023-05-01 12:13:25.503 28819 28848 Error Unity   at UnityEngine.XR.MagicLeap.MLLazySingleton`1[T].get_Instance () [0x00021] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\Common\MLLazySingleton.cs:31 
2023-05-01 12:13:25.503 28819 28848 Error Unity   at UnityEngine.XR.MagicLeap.MLPermissions.RequestPermission (System.String permission, UnityEngine.XR.MagicLeap.MLPermissions+Callbacks callbacks) [0x00000] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\APIs\Permissions\MLPermissions.cs:55 
2023-05-01 12:13:25.503 28819 28848 Error Unity   at MagicLeap.MRTK.SpatialAwareness.MagicLeapSpatialMeshObserver.Enable ()

Update:
We have the same error in the non-MRTK example scene - build from the same project (we have both example packages in our main project).
Through that UI I can re-open the meshing sample scene, and when this is done, the spatial mesh starts up correctly.

Hi @TheMunk, Is the example scene the same as the one in the MagicLeap_Examples project?

Yes. We fresh import both example packages on every SDK update.

After changing some stuff around, I seem to have gotten something working, but only if we start up directly into a scene with meshing enabled.
If not, we get this native crash;
tombstone_00.txt (368.7 KB)
tombstone_01.txt (370.5 KB)
tombstone_02.txt (371.1 KB)

EDIT:
Seems to be the old "SetCustomMeshBlockRequests" bug - now everything seems to work correctly again.
Although still getting some occasional errors in the log;

2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 leapcore/frameworks/perception/services/meshing_manager/client/src/client.cpp(151) GetMeshingDataResponse():
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 ERR: [stack trace begin]
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #00 pc 0000000000014baa  /system/lib64/libml_meshing_manager_client.so (ml::perception::meshing_manager::Client::GetMeshingDataResponse(unsigned long, ml::pil::ss::MeshingMesh*)+1914)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #01 pc 0000000000017bf3  /system/lib64/libml_perception_meshing.so (ml::perception::datasources::BinderMeshingDataSource::GetResponse(unsigned long const&, ml::pil::ss::MeshingMesh*) const+179)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #02 pc 0000000000012804  /system/lib64/libml_perception_meshing.so (ml::perception::components::meshing::Meshing::GetMeshingDataResponse(unsigned long, ml::pil::ss::MeshingMesh*)+164)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #03 pc 0000000000082fc0  /system/lib64/libperception.magicleap.so (MLMeshingGetMeshResult+272)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #04 pc 000000000019b47d  /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libml_sdk_loader.so (_ZN9DelayCallI10perception31MLMeshingGetMeshResultDelayCalliJmmP13MLMeshingMeshEEclEmmS3_+77)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #05 pc 000000000019a96b  /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libml_sdk_loader.so (_Z26MLMeshingGetMeshResultShimIJmmP13MLMeshingMeshEEiDpT_+123)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #06 pc 000000000019a8e4  /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libml_sdk_loader.so (MLMeshingGetMeshResult+36)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #07 pc 00000000000c4a6e  /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (MeshingSubsystem::ProcessPendingBatchRequest()+94)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #08 pc 00000000000c44bf  /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (MeshingSubsystem::GetMeshInfos(UnityXRMeshInfoAllocator*)+575)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #09 pc 00000000000c23b4  /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (_ZZN16MeshingSubsystem10InitializeEPvS0_ENK3$_0clES0_S0_P24UnityXRMeshInfoAllocator+36)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #10 pc 00000000000c2384  /data/app/com.Laerdal.MRTKTest_0_1_20_pre1-qnPeBWQJjg_OKhL_n9hHmg==/lib/x86_64/libMagicLeapXrProvider.so (_ZZN16MeshingSubsystem10InitializeEPvS0_EN3$_08__invokeES0_S0_P24UnityXRMeshInfoAllocator+36)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #11 pc 00000000018c2434  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libunity.so (_ZN18XRMeshingSubsystem12GetMeshInfosEP13dynamic_arrayI8MeshInfoLm0EE+90)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #12 pc 00000000018c3706  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libunity.so (XRMeshingSubsystem::GetMeshInfosAsList(ScriptingObjectPtr)+82)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #13 pc 0000000000b5ec83  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libunity.so (XRMeshSubsystem_CUSTOM_GetMeshInfosAsList(ScriptingBackendNativeObjectPtrOpaque*, ScriptingBackendNativeObjectPtrOpaque*)+150)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #14 pc 000000000e86db35  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (XRMeshSubsystem_GetMeshInfosAsList_m72D6DDE116C761283E51B90D4EBC50D59C395917+69)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #15 pc 000000000e86da3c  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (XRMeshSubsystem_TryGetMeshInfos_m05F584066A873F286C16B99A929C4B3B9AB58FD2+748)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #16 pc 0000000006648122  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (MeshingSubsystemComponent_Update_mF20690A4624CC450EA1F2A42349BDA696F641977+2818)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #17 pc 00000000060bacd9  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (_Z65RuntimeInvoker_TrueVoid_t4861ACF8F4594C3437BB48B6E56783494B843915PFvvEPK10MethodInfoPvPS4_S4_+41)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #18 pc 000000000f00bc7c  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (il2cpp::vm::Runtime::InvokeWithThrow(MethodInfo const*, void*, void**)+92)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #19 pc 000000000f00bbb9  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (il2cpp::vm::Runtime::Invoke(MethodInfo const*, void*, void**, Il2CppException**)+217)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #20 pc 000000000f0e23ec  /data/data/com.Laerdal.MRTKTest_0_1_20_pre1/pram-shadow-files/lib/libil2cpp.so (il2cpp_runtime_invoke+44)
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 #21 pc 00000000012f82d
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 leapcore/frameworks/perception/services/meshing_manager/client/src/client.cpp(363) FreeResourcePrivate():
2023-05-02 09:01:55.130 24259 24281 Error com.Laerdal.MRTKTest_0_1_20_pre1 ERR:  exception: [ Meshing ] Query handle not found

Still have no idea what i changed, so sorry I can't provide more information.

Alright we're still getting the marshal errors whenever we request permissions;

2023-05-03 07:35:07.610 28688 28710 Error Unity NotSupportedException: To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition. The method we're attempting to marshal is: UnityEngine.XR.MagicLeap.MLAutoAPISingleton`1[[UnityEngine.XR.MagicLeap.MLPermissions, MagicLeap.SDK, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::OnPerceptionShutdown
2023-05-03 07:35:07.610 28688 28710 Error Unity   at UnityEngine.XR.MagicLeap.MLPermissions.RequestPermission (System.String permission, UnityEngine.XR.MagicLeap.MLPermissions+Callbacks callbacks) [0x00000] in .\Submodules\MagicLeapSDK\com.magicleap.unitysdk\Runtime\APIs\Permissions\MLPermissions.cs:55 
2023-05-03 07:35:07.610 28688 28710 Error Unity   at SimplePermissionGuaranteer.Awake () [0x00064] in C:\work\magicleap-ann

Which doesn't make any sense, since the MLAutoAPISingleton looks fine;

[AOT.MonoPInvokeCallback(typeof(MagicLeapXrProviderNativeBindings.CallOnPerceptionShutdownDelegate))]
private static void OnPerceptionShutdown() => Instance.StopInternal();

UPDATE:
It seems like some build settings will trigger this error.
I think its the IL2CPP code generation when set to "Faster (smaller) builds" instead of "Faster runtime" or it might be the incremental "patch and run" option in unity. Or maybe the combination.

@TheMunk , have you tried importing this into your project? It will set your project up with the correct options, eliminating any possible error of manually clicking things in the UI? It may help: Magic Leap Setup Tool | Integration | Unity Asset Store