Log in or register to post comments

Exception when initialising targets switching scenes

June 28, 2019 - 7:23am #1

In Unity 2019.1.6f1 with Vuforia (8.3.8) I am getting the following error (intermittently) when I swap between scenes.

I have 2 scenes, Main and Vuforia.  I start on Main.

I go to the Vuforia scene - everything is fine.

I go back to the Main scene - everything is fine.

I go to the Vuforia scene again, I sometimes get the error below:

Any thoughts?

 

This is thrown directly after "Starting Positional Device Tracker." in the Debug Log.

Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: An item with the same key has already been added. Key: 0 at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.StateManager.UpdateTrackablePoses (UnityEngine.Vector3 positionalOffset, UnityEngine.Quaternion rotationalOffset, Vuforia.TrackerData+TrackableResultData[] trackableResultDataArray, Vuforia.TrackerData+VuMarkTargetResultData[] vuMarkResultDataArray, Vuforia.VuforiaManager+TrackableIdPair originTrackableID, System.Int32 frameIndex, System.Boolean updateTrackableStates) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.VuforiaManager.UpdateTrackers (Vuforia.TrackerData+FrameState frameState) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.VuforiaManager.Update (UnityEngine.ScreenOrientation counterRotation, System.Boolean& reapplyOldState) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.VuforiaARController.UpdateStatePrivate (System.Boolean forceUpdate, System.Boolean reapplyOldState) [0x00000] in <00000000000000000000000000000000>:0 at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0 at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.DelegateHelper.InvokeDelegate (System.Delegate action, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 --- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0 at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0 at Vuforia.DelegateHelper.InvokeDelegate (System.Delegate action, System.Object[] args) [0x00000] in <00000000000000000000000000000000>:0

Exception when initialising targets switching scenes

September 3, 2019 - 6:28am #18

Great news, thanks team Vuforia!

Exception when initialising targets switching scenes

September 2, 2019 - 7:03am #17

Hi @iflory

Following up on this thread.

Issue has been fixed starting with 8.5.

Thank you.

Vuforia Engine Support

Exception when initialising targets switching scenes

July 26, 2019 - 1:08pm #16

Hello @iflory,

I did another test using your clarified instructions and hit an error when running in Play Mode on Win 10:

Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: An item with the same key has already been added. Key: 0

  at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000c1] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

  at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

  at Vuforia.StateManager.UpdateTrackablePoses (UnityEngine.Vector3 positionalOffset, UnityEngine.Quaternion rotationalOffset, Vuforia.TrackerData+TrackableResultData[] trackableResultDataArray, Vuforia.TrackerData+VuMarkTargetResultData[] vuMarkResultDataArray, Vuforia.VuforiaManager+TrackableIdPair originTrackableID, System.Int32 frameIndex, System.Boolean updateTrackableStates) [0x00024] in <21bfe61d2ac241f6a9131b858645aad9>:0

  at Vuforia.StateManager.UpdateTrackablePoses (UnityEngine.Vector3 positionalOffset, UnityEngine.Quaternion rotationalOffset, Vuforia.TrackerData+TrackableResultData[] trackableResultDataArray, Vuforia.TrackerData+VuMarkTargetResultData[] vuMarkResultDataArray, Vuforia.VuforiaManager+TrackableIdPair originTrackableID, System.Int32 frameIndex) [0x00000] in <21bfe61d2ac241f6a9131b858645aad9>:0

  at Vuforia.VuforiaManager.UpdateTrackers (Vuforia.TrackerData+FrameState frameState) [0x002a6] in <21bfe61d2ac241f6a9131b858645aad9>:0

  at Vuforia.VuforiaManager.Update (UnityEngine.ScreenOrientation counterRotation, System.Boolean& reapplyOldState) [0x0018c] in <21bfe61d2ac241f6a9131b858645aad9>:0

  at Vuforia.VuforiaARController.UpdateStatePrivate (System.Boolean forceUpdate, System.Boolean reapplyOldState) [0x00061] in <21bfe61d2ac241f6a9131b858645aad9>:0

  at Vuforia.VuforiaARController.UpdateState (System.Boolean forceUpdate, System.Boolean reapplyOldState) [0x0000c] in <21bfe61d2ac241f6a9131b858645aad9>:0

  at Vuforia.DigitalEyewearARController.Update () [0x00000] in <21bfe61d2ac241f6a9131b858645aad9>:0

  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)

  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

   --- End of inner exception stack trace ---

  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <1f0c1ef1ad524c38bbc5536809c46b48>:0

  at Vuforia.DelegateHelper.InvokeDelegate (System.Delegate action, System.Object[] args) [0x0000f] in <21bfe61d2ac241f6a9131b858645aad9>:0
UnityEngine.Debug:LogError(Object)
Vuforia.DelegateHelper:InvokeDelegate(Delegate, Object[])
Vuforia.DelegateHelper:InvokeWithExceptionHandling(Action)
Vuforia.VuforiaBehaviour:Update()

Thanks again for the repro case as this was critical in reproducing. I'll open a bug and report back on this thread with any relevant updates.

-Vuforia Engine Support

Exception when initialising targets switching scenes

July 26, 2019 - 9:38am #15

Hello @iflory,

Thanks for the response. I did try pointing the camera once at the target included in your sample project but it did not seem to do anything.

-Vuforia Engine Support

Exception when initialising targets switching scenes

July 26, 2019 - 3:35am #14

Hi there,

It's happening in both the Editor (Windows 10) using a webcam and also on iPad (iOS  osVersion 12.3.1)

I think it might only happen if you are pointing at the target when you swap.  (I usually point the webcam at the target then do the swapping)

If you still don't manage to reproduce it I'll see if I can video myself doing it so you can see exactly what I'm doing.

Exception when initialising targets switching scenes

July 25, 2019 - 2:40pm #13

Hello @iflory,

Thanks again for the repro project. Sorry that it slipped my mind but I did spend some time on it today.

The app is straightforward and self-explanatory. I ran it on a couple of devices (S8+, Pixel 3), switching between scenes a couple of dozen times as rapidly as I could, but was not able to invoke the failure you observed.

Can you share device models that you used to replicate?

Thanks,

Vuforia Engine Support

 

Exception when initialising targets switching scenes

July 24, 2019 - 12:05pm #12

Hi @iflory,

Thanks for the tip. I did find it in my inbox. I'll take a look.

Thanks,

Vuforia Engine Support

Exception when initialising targets switching scenes

July 24, 2019 - 4:43am #11

Hi Medabit - sorry, I actually direct messaged it to you as it has my targets and key in the project. Hopefully it's sitting in your forum inbox. If not, can you let me know another method of getting it to you rather than posting on here.  Thanks.

Exception when initialising targets switching scenes

July 23, 2019 - 11:05am #10

Hello @iflory,

Can you please clarify how this project was emailed to Vuforia? I don't recall seeing it and would like to find for review.

Thanks,

Vuforia Engine Support

Exception when initialising targets switching scenes

July 23, 2019 - 1:00am #9

I managed to replicate this with a very empty Unity project and have emailed it to Vuforia - hopefully this will help them narrow the issue down.

Exception when initialising targets switching scenes

July 22, 2019 - 12:22pm #8

I got the same exception as you iflory! It's very frustrateing!? 

I'm thinking is has to do with the class Vuforia.StateManager. The console writes that it found x amount of new tracking targets after vuforia init. I got 10 targets pr. scene, and some of the targets are the same in both scenes.

Everytime i switch scene, every target gets added to some kind of dictionary with their own ID. first time they are ID 1-10, second time it's 11-20 and so forth. But sometimes it seems that Vuforia adds an ID key that already excists? But how do we "Force" Vuforia to not add the targets to the dataset again? We can't delete the dataset, that's not allowed because we use an external dataset.



Hmmm, what to do? any thoughts anyone? I'm also very interested in useing the extended tracking, but sometimes this error pops up.

 

 

Exception when initialising targets switching scenes

July 3, 2019 - 9:57am #7

Hello,

We've been unable to replicate using our Core Samples. If you get that "spare" moment and can share you bare scene app that demonstrates the issue, that'd be extremely helpful.

Thanks,

Vuforia Engine Support

Exception when initialising targets switching scenes

July 3, 2019 - 3:32am #6

Hi there,

I don't think this is the problem.  Everything works great first time round - you go from Main scene to the Vuforia scene, the target pops up, no errors listed. Perfect.  The issue is if you then go back to the Main scene then back in to the Vuforia one it intermittently throws the exception listed below.  It's a "going back to the Vuforia scene a second time" issue.

If I [ever] get a spare moment I'll strip my app back to the bare scenes and make sure nothing else is affecting it.

Exception when initialising targets switching scenes

July 2, 2019 - 9:12am #5

Hello,

Note that Vuforia Engine 7.2 (and beyond) made changes to the initialization process that may impact the flow of your application. The default initialization behavior of Vuforia Engine is to download the latest device profile in order to deliver the best experience on the device.  Depending on the speed of the user's internet, this could add several seconds to application load. This only occurs the very first time the user launches the app and will not impact application loading in future launches of the app.

It is strongly recommended to allow the Vuforia Engine to fetch the latest device profile. Developers looking to disable this behavior should set the following hint before initializing Vuforia: VuforiaUnity.SetHint(VuforiaHint.HINT_ASYNC_FETCH_OF_LATEST_CALIBRATION, 1);

Native migration guide: https://library.vuforia.com/content/vuforia-library/en/articles/Solution/how-migrate-vuforia-7_2.html

Unity migration guide: https://library.vuforia.com/content/vuforia-library/en/articles/Solution/How-To-Migrate-a-Unity-Project.html

Note that in Unity, there are a few different ways to determine the status of Vuforia initialization:

  • Vuforia has initialized (before trackers and camera are started): VuforiaARController.Instance.RegisterVuforiaInitializedCallback(OnVuforiaInitialized);
  • Vuforia trackers and camera have started: VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
  • bool hasVuforiaStarted = VuforiaARController.Instance.HasStarted;

Thanks,

Vuforia Engine Support

Exception when initialising targets switching scenes

July 2, 2019 - 2:24am #4

Timed it - quickest I can get from de-initialisation of the Vuforia scene to Main and back is > 6 seconds.

 

Exception when initialising targets switching scenes

July 2, 2019 - 1:04am #3

Hi Team Vuforia,

Yes, the main scene does not have a Vuforia Camera.  I have tried initialising Vuforia in its scene both automatically and manually (with VuforiaRuntime.Instance.InitVuforia(); after a short delay)

It's an interesting thought about the race condition - that could definitely be possible I guess.  I think the fastest I can go from my Main scene to the Vuforia one is 3-4 seconds as I have to enter a keycode first.

If there is a race condition, what would you suggest as a good solution?

Many thanks for your help.

Exception when initialising targets switching scenes

July 1, 2019 - 11:41am #2

Hello,

Is it correct that the "Main" scene *does not* have a Vuforia ARCamera? If that's correct, this could be a race condition between Vuforia init'ing and deinit'ing as you enter and exit the scene with the ARCamera.

Are you doing this swap quickly?

Thanks,

Vuforia Engine Support

Log in or register to post comments