Log in or register to post comments

marker.MarkerID issue, always returns NullReferenceException

February 18, 2013 - 7:55pm #1

I'm probably just doing something stupid, but I can't figure out what.

 

In a custom TrackableEventHandler:

 

/// <summary>

/// A custom handler that implements the ITrackableEventHandler interface.

/// </summary>

public class TrackableEventHandlerPOI : MonoBehaviour,

                                            ITrackableEventHandler

{

    #region PRIVATE_MEMBER_VARIABLES

 

    private TrackableBehaviour mTrackableBehaviour;

private MarkerBehaviour mMarkerBehaviour;

    

    #endregion // PRIVATE_MEMBER_VARIABLES

 

 

private MarkerBehaviour mMarkerBehaviour;

[...]
 

mMarkerBehaviour = GetComponent<MarkerBehaviour>();

[...]
 
and in OnTrackingFound(){

Debug.Log("Trackable " + mMarkerBehaviour.Marker.MarkerID + " found");

}
 
mMarkerBehaviour.Marker.MarkerID Always throws a NullReferenceException.
 
I think I'm just missing something obvious but I'm too tired to see it.  Any help is appreciated.

 

marker.MarkerID issue, always returns NullReferenceException

December 5, 2013 - 1:31am #23

I found a solution for first issue, it works with

"Trackable.ID" (in DefaultTrackableEventHandler script)

What I didn't find is, how to assign particular gameobject on detection of that particular image. I am able to do the same but not for the desired images, all my objects are being augmented on only one image. How can I solve this issue?

Has anyone done this?? Any help is much appreciated. Thanks!
 
Jainam

marker.MarkerID issue, always returns NullReferenceException

November 25, 2013 - 3:42am #22

I am a noob in vuforia. I want to know which image is being tracked from the list in the XML file and I guess, adding  

MarkerBehaviour marker = (MarkerBehaviour) mTrackableBehaviour;
Debug.Log("Trackable " + marker.Marker.MarkerID + " found");

at the end of OnTrackingFound method ( in the DefaultTrackableEventHandler script) would give me the same. But this gives me this error,

InvalidCastException: Cannot cast from source type to destination type.
DefaultTrackableEventHandler.OnTrackingFound () (at Assets/Qualcomm Augmented Reality/Scripts/DefaultTrackableEventHandler.cs:91)
DefaultTrackableEventHandler.OnTrackableStateChanged (Status previousStatus, Status newStatus) (at Assets/Qualcomm Augmented Reality/Scripts/DefaultTrackableEventHandler.cs:58)
TrackableBehaviour.OnTrackerUpdate (Status newStatus) (at Assets/Qualcomm Augmented Reality/Scripts/TrackableBehaviour.cs:142)
StateManagerImpl.UpdateTrackablePoses (UnityEngine.Camera arCamera, .TrackableResultData[] trackableResultDataArray, Int32 originTrackableID, Int32 frameIndex) (at Assets/Qualcomm Augmented Reality/Scripts/Internal/StateManagerImpl.cs:497)
QCARManagerImpl.UpdateTrackers (FrameState frameState) (at Assets/Qualcomm Augmented Reality/Scripts/Internal/QCARManagerImpl.cs:485)
QCARManagerImpl.Update (ScreenOrientation counterRotation, CameraDeviceMode deviceMode, .VideoModeData& videoMode) (at Assets/Qualcomm Augmented Reality/Scripts/Internal/QCARManagerImpl.cs:291)
QCARBehaviour.Update () (at Assets/Qualcomm Augmented Reality/Scripts/QCARBehaviour.cs:441)
 
What I am trying to do is, I want to augment a certain object on detection of a certain image and so I need to know the ID of image being tracked. I also have no clue how to assign particular gameobject on detection of that particular image. I am able to do the same but not for the desired images, all my objects are being augmented on only one image. How can I solve this issue?
 
Any help would be much appreciated. Thanks in advance!
 
Jainam

marker.MarkerID issue, always returns NullReferenceException

March 6, 2013 - 11:21pm #21

You're welcome.

marker.MarkerID issue, always returns NullReferenceException

March 6, 2013 - 4:32pm #20

Thanks elecman and Alessandro.  Most appreciated!

marker.MarkerID issue, always returns NullReferenceException

March 4, 2013 - 2:38am #19

cap10subtext:

indeed, 2.0.31 is out and contains a fix for that issue (so you don't need to apply the workaround anymore, as elecman said)

marker.MarkerID issue, always returns NullReferenceException

March 2, 2013 - 3:41am #18

Good to hear that it works. Glad to help :-)

Edit:
Vuforia version 2.0.31 is just released and those two lines are not needed anymore.

marker.MarkerID issue, always returns NullReferenceException

February 26, 2013 - 10:43am #17

Thank you!!!!!!!!!   Elecman thank you so much for this.  I'll try it out.

If this works you've really saved my bacon.

 

EDIT: THIS WORKS!!!  Thanks so much, elecman!  You really helped me out!

marker.MarkerID issue, always returns NullReferenceException

February 25, 2013 - 11:46pm #16

Thanks Elecman for posting the workaround.

marker.MarkerID issue, always returns NullReferenceException

February 25, 2013 - 7:38pm #15

As a quick fix, you might want to try adding these two lines after you have created all the frame markers:

StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();
stateManager.AssociateMarkerBehaviours();

I had a similar issue and this resolved it. Have a look at UCS which creates frame markers at runtime successfully:
https://developer.vuforia.com/forum/qcar-api/unified-coordinate-system

 

marker.MarkerID issue, always returns NullReferenceException

February 21, 2013 - 11:02am #14

You're welcome. I will ping you when we have a release.

marker.MarkerID issue, always returns NullReferenceException

February 21, 2013 - 10:59am #13

Okay, thanks for the update.  Thanks so much for your assistance and will await an update with great anticipation.

marker.MarkerID issue, always returns NullReferenceException

February 21, 2013 - 10:45am #12

Hi, quick update; by analyzing the issue, I figured out this is due to the state of runtime-created Markers not being updated properly by the tracker;

this issue has been addressed recently by the SDK team; so a fix is normally expected for the next update of the SDK (and Unity extension); at the moment I cannot be precise on a possible release date (but it is expected relatively soon).

 

marker.MarkerID issue, always returns NullReferenceException

February 20, 2013 - 11:12am #11

Hi, thanks for the update; I will try to reproduce it and check with our engineering team as well.

I will report back then (feel free to ping me again if you don't hear back very soon).

 

marker.MarkerID issue, always returns NullReferenceException

February 20, 2013 - 10:03am #10

I have added as you've suggested and performed the same control test.  OnTrackableStateChanged is not being called for the runtime generated markers.:

1.  When a FrameMarker is added to the scene as a Prefab with TrackableEventHandlerPOI, OnTrackableStateChanged is called when the frameTarget enters the camera frame.

2.  When a FrameMarker is added by script from MarkerController and assigned TrackableEventHandlerPOI it does not report OnTrackableStateChanged except for one report when the Scene is stopped in Unity and all markers are reported lost.  TrackableEventHandlerPOI seems to be added properly because it reports that it's in play.  The only way I know the markers are being detected is because the absolute number of markers in the scene is being reported from InitializeTrackableContainer in QCARManagerImpl.

Thanks for your help with this!  I appreciate your patience!

 

 

 

 

marker.MarkerID issue, always returns NullReferenceException

February 20, 2013 - 9:10am #9

Hi, could you add this line right at the beginning of your OnTrackableStateChanged function:

Debug.Log("OnTrackableStateChanged has been called");

And then could you try to loose and re-detect the markers a few times, by moving your camera, and check the logs to see if the OnTrackableStateChanged is called at any of these steps ?

 

marker.MarkerID issue, always returns NullReferenceException

February 20, 2013 - 6:57am #8

Here you go.  There's nothing special about it.  Here's what I've done to test this so far.  I have FrameMarkers that are constructed at runtime and Prefabs in the scene.  Those created with Prefabs have TrackableEventHandlerPOI replacing DefaultTrackableEventHandler.  When I show the FrameTargets to the webcam in PlayMode, the targets that have been created from Prefabs report the Marker.MarkerID and Trackable.Name (from the Debug.Log lines in TrackableEventHandlerPOI).  Those that were created at Runtime do not report.  I have a little Debug that Says "TBPOI is in Play" on start and that's appearing in the Console as the TrackableEventHandlerPOI is assigned by the MarkerController.

Let me know if I can provide any more info.

 

/*==============================================================================
            Copyright (c) 2010-2012 QUALCOMM Austria Research Center GmbH.
            All Rights Reserved.
            Qualcomm Confidential and Proprietary
==============================================================================*/

using UnityEngine;
using System.Collections.Generic;
using System.Linq;

//pull in an SceneIndex array from another class and load with marker IDs

/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// </summary>
public class TrackableEventHandlerPOI : MonoBehaviour,
                                            ITrackableEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES
 
    private TrackableBehaviour mTrackableBehaviour;
	private MarkerBehaviour mMarkerBehaviour;
    
    #endregion // PRIVATE_MEMBER_VARIABLES



    #region UNTIY_MONOBEHAVIOUR_METHODS
    
    void Start()
    {
		Debug.Log("TBPOI is in play!");
		
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }
		
		mMarkerBehaviour = GetComponent<MarkerBehaviour>();
		
		if (mMarkerBehaviour==null)
        {
           Debug.Log ("Marker Behaviour NOT found!");
        }
		
        OnTrackingLost();
    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS



    #region PUBLIC_METHODS
	
    /// <summary>
    /// Implementation of the ITrackableEventHandler function called when the
    /// tracking state changes.
    /// </summary>
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED)
        {
            OnTrackingFound();
        }
        else
        {
            OnTrackingLost();
        }
    }

    #endregion // PUBLIC_METHODS



    #region PRIVATE_METHODS


    private void OnTrackingFound()
    {
		Debug.Log("Trackable " + mMarkerBehaviour.Marker.MarkerID + " found");		
		Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    }


    private void OnTrackingLost()
    {
		
		Debug.Log("Trackable " + mMarkerBehaviour.Marker.MarkerID + " lost");
        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    }

    #endregion // PRIVATE_METHODS
}

 

marker.MarkerID issue, always returns NullReferenceException

February 20, 2013 - 4:47am #7

Hi, can you share the cod of your TrackableEventHandlerPOI script ?

 

marker.MarkerID issue, always returns NullReferenceException

February 19, 2013 - 12:31pm #6

Thanks for confirming this.  I'm testing it now but for some reason the TrackableEventHandler only seems to work if the prefab is sitting in the scene.

Can TrackableEventHandlers be assigned at Runtime (maybe by adjusting the script compliation order)?  The marker looks okay in the inspector, but when I show the markerTargets to the camera, it tells me the absolute number of trackables but doesn't report the OnTrackableLost() or OnTrackableFound() reports except at launch and stop (when it just reports lost).  Am I missing a step setting up my MarkerTargets?

 

MarkerTracker markerTracker = (MarkerTracker)TrackerManager.Instance.GetTracker(Tracker.Type.MARKER_TRACKER);
        			MarkerBehaviour mb = markerTracker.CreateMarker(_poi.MarkerNumber, "marker" + _poi.MarkerNumber, 100);
					if (mb){ 
						mb.gameObject.AddComponent<TurnOffBehaviour>();
						mb.gameObject.AddComponent<TrackableEventHandlerPOI>();
						
			
						Debug.Log("added to tracker" + mb.name);
						
					} else {
						Debug.Log("Failed.");
					}

 

marker.MarkerID issue, always returns NullReferenceException

February 19, 2013 - 8:40am #5

Hi, as you correctlty spotted, you must enable PlayMode to have proper behaviour, indeed;

however this is the normal behaviour, it is not a bug, as I double-checked with the engineering team.

 

marker.MarkerID issue, always returns NullReferenceException

February 19, 2013 - 7:09am #4

Okay, I may be on to something.  I decided to move on to the next part of this project which was to create the FrameMarkers dynamically.  I normally deactivate playmode because it never seems to work properly (the Videotexture is always off in la-la land and I just get a white screen).  However, that made everything start reporting properly.  Apparently it has to be in runtime to report marker.MarkerID.

This seems like a bug, as I would assume that, like the ImageTarget trackerbehaviour, it should report even in testing (just by hitting play, regardless of if PlayMode is enabled).  Should I file a bug report?

marker.MarkerID issue, always returns NullReferenceException

February 19, 2013 - 5:54am #3

Hi Alessandro,

 

Thanks for replying but still no luck.  mMarkerBehaviour was located in Start() and is NOT null (I've also tried if (!mMarkerBehaviour) just to be thorough), and Marker.MarkerID autocomplete in MonoDevelop.  

I'm going to take a look at it again with fresh eyes and a cup of coffee but nothing's jumping out at me... it looks like it should work (unless, is there another class that needs to be inherited?)  

Here's the complete code:

/*==============================================================================
            Copyright (c) 2010-2012 QUALCOMM Austria Research Center GmbH.
            All Rights Reserved.
            Qualcomm Confidential and Proprietary
==============================================================================*/

using UnityEngine;
using System.Collections.Generic;
using System.Linq;


/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// </summary>
public class TrackableEventHandlerPOI : MonoBehaviour,
                                            ITrackableEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES
 
    private TrackableBehaviour mTrackableBehaviour;
	private MarkerBehaviour mMarkerBehaviour;
    
    #endregion // PRIVATE_MEMBER_VARIABLES



    #region UNTIY_MONOBEHAVIOUR_METHODS
    
    void Start()
    {
		
		
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }
		
		mMarkerBehaviour = GetComponent<MarkerBehaviour>();
		
		if (mMarkerBehaviour==null)
        {
           Debug.Log ("Marker Behaviour NOT found!");
        }
		
        OnTrackingLost();
    }

    #endregion // UNTIY_MONOBEHAVIOUR_METHODS



    #region PUBLIC_METHODS

    /// <summary>
    /// Implementation of the ITrackableEventHandler function called when the
    /// tracking state changes.
    /// </summary>
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED)
        {
            OnTrackingFound();
        }
        else
        {
            OnTrackingLost();
        }
    }

    #endregion // PUBLIC_METHODS



    #region PRIVATE_METHODS


    private void OnTrackingFound()
    {
		
   
		Debug.Log("Trackable " + mMarkerBehaviour.Marker.MarkerID + " found");
		Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
    }


    private void OnTrackingLost()
    {
		
	
	
	         Debug.Log("Trackable " + mMarkerBehaviour.Marker.MarkerID + " lost");
                 Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    }

    #endregion // PRIVATE_METHODS
}

 

marker.MarkerID issue, always returns NullReferenceException

February 18, 2013 - 10:22pm #2

Hi, your call to "mMarkerBehaviour = GetComponent<MarkerBehaviour>();" should be located inside the Start() method; if not, plase move it there;

also, right after calling it, add a Debug.Log line to check if it is null:

void Start() {

  mMarkerBehaviour = GetComponent<MarkerBehaviour>();
  if (mMarkerBehaviour == null) {
     Debug.Log("Marker Behaviour NOT found (null)");
  }
}

 

Log in or register to post comments