ARDK3: Crashes App with "Failed to load plugin. Plugin loading is only allowed on main thread."

Thanks. I wish you guys fix MeshingModule issue that the meshesChanged doesn’t get invoked. There seems ARMeshManager keeps updating the mesh but ARDK MeshingModule doesn’t update vertices in second load. Maybe some sort of reset interface is needed in ARDK side I guess.

Until then, I’ll stick with my workaround.

Thanks

– JK

In my app, the following workaround seems to work with UaaL on iOS devices.
Please note that I don’t fully understand all the details, so use this at your own risk.

1. Disable plugin registration in RegisterPlugin.mm

// Runtime/Plugins/iOS/RegisterPlugin.mm
-(void)applicationDidFinishLaunching:(NSNotification*) notification
{
    NSLog(@"[Override_iOS applicationDidFinishLaunching:%@]", notification);
    // Do not register here.
    // UnityRegisterRenderingPluginV5(&UnityPluginLoad, &UnityPluginUnload);
}
@end

2. Add plugin loading function to LightshipARDK.m called from Unity.

// Runtime/Plugins/iOS/LightshipARDK.m
void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API LightshipARDK_LoadPluginFromUnity()
{
    NSLog(@"LightshipARDK_LoadPluginFromUnity");
    UnityRegisterRenderingPluginV5(&UnityPluginLoad, &UnityPluginUnload);
}

@interface LightshipARDK : NSObject

+ (void)loadPlugin;
...

3. Call LightshipARDK_LoadPluginFromUnity from Unity

Add LoadPluginFromUnity

// Runtime/Core/LightshipUnityContext.cs
public class LightshipUnityContext
{
    [DllImport("__Internal", EntryPoint = "LightshipARDK_LoadPluginFromUnity")]
    public static extern void LoadPluginFromUnity();

and call it from Initialize method.

    internal static void Initialize(bool isDeviceLidarSupported, bool disableTelemetry = false, string featureFlagFilePath = "")
    {
#if NIANTIC_LIGHTSHIP_AR_LOADER_ENABLED
        // load plugin on initialize
        Debug.Log("LoadPluginFromUnity start")
        LoadPluginFromUnity();
        Debug.Log("LoadPluginFromUnity end")

1 Like

Thank you all. These solutions work in my app.

I added minor changes. no need to change LightshipARDK.m

1.Disable registration on applicationDidFinishLaunching and add loading function.
RegisterPlugin.mm

...
#import "IUnityInterface.h"

// $EDIT: add function for load plugin from Unity
#ifdef __cplusplus
extern "C" {
#endif
void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API LightshipARDK_LoadPluginFromUnity()
{
    NSLog(@"LightshipARDK_LoadPluginFromUnity");
    UnityRegisterRenderingPluginV5(&UnityPluginLoad, &UnityPluginUnload);
}
#ifdef __cplusplus
} // extern "C"
#endif
...
-(void)applicationDidFinishLaunching:(NSNotification*) notification
{
    NSLog(@"[Override_iOS applicationDidFinishLaunching:%@]", notification);
    // $EDIT: for manual load plugin from Unity
    // UnityRegisterRenderingPluginV5(&UnityPluginLoad, &UnityPluginUnload);
}

2.Call LightshipARDK_LoadPluginFromUnity from Unity.
LightshipUnityContext.cs

...
    public class LightshipUnityContext
    {
# if UNITY_IOS && !UNITY_EDITOR
        /// <summary>
        /// $EDIT: Manual load plugin by added function
        /// https://community.nianticspatial.com/t/ardk3-crashes-app-with-failed-to-load-plugin-plugin-loading-is-only-allowed-on-main-thread/5527/22
        /// </summary>
        /// <returns></returns>
        [DllImport("__Internal", EntryPoint = "LightshipARDK_LoadPluginFromUnity")]
        public static extern void LoadPluginFromUnity();
#endif
...
        internal static void Initialize(bool isDeviceLidarSupported, bool disableTelemetry = false, string featureFlagFilePath = "")
        {
#if NIANTIC_LIGHTSHIP_AR_LOADER_ENABLED
# if UNITY_IOS && !UNITY_EDITOR
            // $EDIT: load plugin on initialize
            Debug.Log("LoadPluginFromUnity start");
            LoadPluginFromUnity();
            Debug.Log("LoadPluginFromUnity end");
#endif