PTCInc / vuforia-engine

Bug and feedback issue tracker for the Vuforia Engine SDK
https://developer.vuforia.com
20 stars 0 forks source link

ObserverFactory.CreateImageTarget throws NullReferenceException on iOS #147

Closed mrrenaud closed 2 months ago

mrrenaud commented 3 months ago

Summarize the bug:

ObserverFactory.CreateImageTarget(string databasePath, string targetName) throws exception on iOS, while ObserverFactory.CreateImageTargetAsync(string databasePath, string targetName) works well.

Observed problem

When creating image target from a database in the local StreamingAsset folder, it fails to create the target if we use the synchronous CreateImageTarget method.

However, using the CreateImageTargetAsync version doesn't throw and creates the target as expected.

Expected result Both methods should succeed.

Other observations On Android, both versions of the method works well. It only fails on iOS.

Reproducible steps Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Affected Vuforia Engine version: v10.25.4.

Affected platform:

Affected device:

Device or platform logs

Log with errors :

Trying to load /private/var/containers/Bundle/Application/********-****-****-****-************/*.app/Data/Raw/Vuforia/allcovers.xml with ********

NullReferenceException: Object reference not set to an instance of an object.
  at Vuforia.Internal.Core.ObserverFactory.<CreateImageTargetObserver>g__CreateAndConfigureObserver|18_0 (Vuforia.Internal.Core.ObserverFactory+<>c__DisplayClass18_0& ) [0x00000] in <00000000000000000000000000000000>:0 
  at Vuforia.Internal.Core.ObserverFactory.CreateImageTargetObserver (System.String datasetPath, System.String targetName, System.Nullable`1[T] trackingOptimization) [0x00000] in <00000000000000000000000000000000>:0 
  at Vuforia.ObserverFactory.CreateImageTarget (System.String databasePath, System.String targetName) [0x00000] in <00000000000000000000000000000000>:0 
  at Scripts.AR.DynamicTargets.StartTracking () [0x00091] in /Users/sparkle/git/*******/*******-new/*******/Assets/Scripts/AR/DynamicTargets.cs:36 
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00000] in <00000000000000000000000000000000>:0 
  at Scripts.AR.DynamicTargets.StartTracking () [0x00000] in <00000000000000000000000000000000>:0 
  at Scripts.Periods.PageController.Start () [0x00086] in /Users/sparkle/git/*******/*******-new/*******/Assets/Scripts/PageController.cs:57 
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
Scripts.AR.<StartTracking>d__6:MoveNext() (at /Users/sparkle/git/*******/*******-new/*******/Assets/Scripts/AR/DynamicTargets.cs:51)
System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start(<StartTracking>d__6&)
Scripts.AR.DynamicTargets:StartTracking()
Scripts.Periods.PageController:Start() (at /Users/sparkle/git/*******/*******-new/*******/Assets/Scripts/PageController.cs:57)

Failed loading asset /private/var/containers/Bundle/Application/********-****-****-****-

Working log :

Trying to load /private/var/containers/Bundle/Application/********-****-****-****-************/*.app/Data/Raw/Vuforia/allcovers.xml with 2019_L_*****

2024-08-22 14:16:38.954672+0200 *******[2145:1059271] INFO/AR(2145) Creating ImageTargetObserver...
2024-08-22 14:16:38.955441+0200 *******[2145:1059271] INFO/AR(2145) Created new observer with ID '51'
2024-08-22 14:16:38.955551+0200 *******[2145:1059271] INFO/AR(2145) Creating ImageTargetObserver...SUCCESS
2024-08-22 14:16:38.975011+0200 *******[2145:1058866] INFO/AR(2145) Activating observer...
2024-08-22 14:16:38.975726+0200 *******[2145:1058866] INFO/AR(2145) Activated observer with ID '51'
2024-08-22 14:16:38.976084+0200 *******[2145:1058866] INFO/AR(2145) Activating observer...SUCCESS
Loaded successfully 2019_L_*****

Workaround Always use the *Async method

Additional comments //

ptc-thesbyro commented 3 months ago

Hi @mrrenaud,

Thank you for reaching out.

We will try to reproduce the issue and get back to you once we have an update.

ptc-epassaro commented 3 months ago

Hi @mrrenaud,

I was not able to reproduce the issue with the sync version of the method. Would it be possible for you to give us some more info on how you encountered the problem?

It would be really helpful for us to know which version of iOS is installed on your device and which version of Xcode you're using to build the project. Also, is this something that happens with any dataset (even the default VuforiaMars_Image database) or only with a specific one? And finally, would it be possible for you to send us an example of the code in which you're using the methods?

Thank you!

mrrenaud commented 3 months ago

I'll try to give you a repro as soon as possible !

ChasingD commented 3 months ago

I have the same problem on hololens2

    private async void CreateImageTarget(Texture2D texture)
    {
        if (texture == null)
        {
            Debug.LogError("AR Texture is null");
        }
        var mTarget = await VuforiaBehaviour.Instance.ObserverFactory.CreateImageTargetAsync(
            texture,
            0.1f,
            "ar");
    }

error is samilar

NullReferenceException: Object reference not set to an instance of an object. at Vuforia.Internal.Core.ObserverFactory.g__CreateAndConfigureObserver|18_0 (Vuforia.Internal.Core.ObserverFactory+<>c__DisplayClass18_0& ) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.Internal.Core.ObserverFactory.CreateImageTargetObserver (System.String datasetPath, System.String targetName, System.Nullable`1[T] trackingOptimization) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.ObserverFactory.CreateImageTarget (System.String databasePath, System.String targetName) [0x00000] in <00000000000000000000000000000000>:0

ptc-epassaro commented 3 months ago

Hi @ChasingD, thank you for your report. We are still not able to reproduce the issue, but I'm wondering what would happen if you called the method with the additional TrackingOptimization argument. Could you please try to call the method like this? VuforiaBehaviour.Instance.ObserverFactory.CreateImageTargetAsync(texture, 0.1f, "ar", TrackingOptimization.DEFAULT);

Also, for completeness, which version of Unity are you using?

ChasingD commented 2 months ago

Hi @ChasingD, thank you for your report. We are still not able to reproduce the issue, but I'm wondering what would happen if you called the method with the additional TrackingOptimization argument. Could you please try to call the method like this? VuforiaBehaviour.Instance.ObserverFactory.CreateImageTargetAsync(texture, 0.1f, "ar", TrackingOptimization.DEFAULT);

Also, for completeness, which version of Unity are you using?

thanks for you reply! hololens2, unity 2022.3.34, vuforia 10.24.4 but i can't call method VuforiaBehaviour.Instance.ObserverFactory.CreateImageTargetAsync(texture, 0.1f, "ar", TrackingOptimization.DEFAULT); there is no method.

ptc-epassaro commented 2 months ago

Hi @ChasingD, I got some APIs mixed up, my bad.

I have a couple more questions, because the issue is still not reproducible on my side:

  1. Are you trying to create more than one target at the same time?
  2. At which point of the Vuforia lifecycle are you trying to create the targets? Is Vuforia initialized and started?
  3. Would it be possible for you to send us an example of the code in which you are calling the private async void CreateImageTarget(Texture2D texture) method that you added in your previous comment?
ChasingD commented 2 months ago

Hi @ChasingD, I got some APIs mixed up, my bad.

I have a couple more questions, because the issue is still not reproducible on my side:

  1. Are you trying to create more than one target at the same time?
  2. At which point of the Vuforia lifecycle are you trying to create the targets? Is Vuforia initialized and started?
  3. Would it be possible for you to send us an example of the code in which you are calling the private async void CreateImageTarget(Texture2D texture) method that you added in your previous comment?

hi @ptc-epassaro , my bad. I solved the problem: i build the app to arm. it works in arm64. could vuforia support arm platform?

ptc-epassaro commented 2 months ago

Hi @ChasingD, glad to know that it works on ARM64! For UWP the only supported architectures are ARM64 and x64.

Unfortunately there's no plan to support 32-bit ARM in the future, as Microsoft themselves are also on the way to deprecate ARM 32-bit. If possible for you, I would also recommend you to only use ARM64.

Thank you for your update!

ptc-epassaro commented 2 months ago

Hi @mrrenaud, are you still facing this issue or do you have a more detailed repro case? We are not able to reproduce it on our side.

ptc-epassaro commented 2 months ago

Closing this issue due to inactivity. Feel free to reopen it if the problem persists.