Log in or register to post comments

Multiple listeners on RegisterTrackableEventHandler

January 26, 2015 - 1:23am #1

Vuforia SDK Version: 3.x -

Description with steps to reproduce:

Hei,

The following is happeing in Unity editor.

When trying to register two listeners to the RegisterTrackEventHandler, the first one goes fine but the second one thorws this on registration:

InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.Generic.List`1+Enumerator[ITrackableEventHandler].VerifyState () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:778)
System.Collections.Generic.List`1+Enumerator[ITrackableEventHandler].MoveNext () (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:784)
TrackableBehaviour.OnTrackerUpdate (Status newStatus)
DataSetTrackableBehaviour.OnTrackerUpdate (Status newStatus)
StateManagerImpl.UpdateTrackablePoses (UnityEngine.Camera arCamera, .TrackableResultData[] trackableResultDataArray, Int32 originTrackableID, Int32 frameIndex)
QCARManagerImpl.UpdateTrackers (FrameState frameState)
QCARManagerImpl.Update (ScreenOrientation counterRotation)
QCARAbstractBehaviour.Update ()

 

The code I am using is fairly straightoforward:

private void Init(bool register) {	
	Debug.Log ("Registering LocalTrackTarget");
	TrackableBehaviour trackableBehaviour = GetComponent<TrackableBehaviour>();
        if (trackableBehaviour != null) {			
		trackableBehaviour.RegisterTrackableEventHandler(this);
	}			
		
	TouchInputManager.Instance.RegisterTrackableBehaviour();
}

And this is on the TouchInputManager:

public void RegisterTrackableBehaviour(){
	Debug.Log("RegisterTrackableBehaviour");
	TrackableBehaviour trackableBehaviour = FindObjectOfType<TrackableBehaviour>();
	if (trackableBehaviour != null) 
	{		
		Debug.Log("RegisterTrackableBehaviour registered");
		trackableBehaviour.RegisterTrackableEventHandler(this);
	}
}

The input I get is 

  • "Registering LocalTrackTarget"
  • "RegisterTrackableBehaviour"
  • "RegisterTrackableBehaviour registered"
  • Exception is thrown

The exception is not showing up again but am I doing somethig wrong in there?

-

Development OS (Mac OS X, Windows, Linux): Mac OS X - Unity -

Mobile OS and Version: iOS 7 -

Mobile Device Manufacturer and Model name: Apple iPhone -

Do the Vuforia Sample Applications show the same behavior?:

Multiple listeners on RegisterTrackableEventHandler

January 28, 2015 - 2:09am #3

Alright for trying but I think I got the issue.

 

Fact is, I am taking over someone else code (and it is not the best of the code I have seen) and it seems the Init method running the registration is called first in the Start and also in the OnLevelWasLoaded.

 

So that could come from this.

Multiple listeners on RegisterTrackableEventHandler

January 27, 2015 - 5:40pm #2

A few things:

1. Move your last Debug.Log() below the register call:
 

if (trackableBehaviour != null)
{      
    trackableBehaviour.RegisterTrackableEventHandler(this);

    // Tip: Don't log success before running the actual command
    Debug.Log("RegisterTrackableBehaviour registered");
}

2. Does your TouchInputManager class implement the ITrackableEventHandler interface?

https://developer.vuforia.com/resources/api/unity/interface_i_trackable_event_handler

3. Are you guaranteed that FindObjectOfType() is going to get the same instance of the trackableBehaviour as before? You might want to pass an instance of the TouchInputManager class to the trackableBehaviour.RegisterTrackableEventHandler():

TrackableBehaviour trackableBehaviour = GetComponent<TrackableBehaviour>();
if (trackableBehaviour != null) {          
    trackableBehaviour.RegisterTrackableEventHandler(this);
    trackableBehaviour.RegisterTrackableEventHandler(TouchInputManager.Instance);
}

 

Log in or register to post comments