Nuitrack called with in WinForms App

Hello Everyone…

I’m new with Nuitrack and C#, however I developed an app in Winforms from where I use Nuitrack to collect data about the position of some joints.

To do this, inside the main Form I call a Form where the Nuitrack code runs. So far so good, I can get the data I want without problems.

The problem arises when I close the nuitrack form to complete the task I intend to complete. Because when I call the Nuitrack form again without closing the main Form, an error occurs and will not allow me to continue with the App.

The error is as follows:

Managed Debugging Assistant ‘CallbackOnCollectedDelegate’: ‘A callback was made to an unused delegate of type’ nuitrack.net! Nuitrack.NativeImporter + OnIssueTrackerUpdateCallback :: Invoke '. This can lead to application crashes, corrupted data, and lost data. When passing delegates to unmanaged code, the managed application must keep them active until they are sure they will never be called again. '

on

try
** {**
** Nuitrack.Update(_skeletonTracker);**
** }**

and if I pressed “Continue” appear the follow error:

System.NullReferenceException: 'The object reference was not defined as an instance of an object.'

also in

try
** {**
** Nuitrack.Update(_skeletonTracker);**
** }**

Anyone have any idea what might be happening?
I’ve already researched the probable reasons for this error. There is information for similar cases, but I could not figure out how to solve my particular case.

The code I use to start and quit Nuitrack runs through 2 buttons and is as follows:

// Button for begin training session
        private void btnIniciarTreino_Click(object sender, EventArgs e)
        {
            
            //----------------------------------------------------------------------------------------------
              NuitrackForm formNuitrack = new NuitrackForm(this);

            formNuitrack.FormBorderStyle = FormBorderStyle.None;
            formNuitrack.TopLevel = false;
            formNuitrack.AutoScroll = true;

            tableLayoutPanelNuitrack.Controls.Add(formNuitrack);
            formNuitrack.Show();

            //----------------------------------------------------------------------------------------------
        }


        // Button for end training session
        private void btnTerminarTreino_Click(object sender, EventArgs e)
        {
            //Close the Form Nuitrack
           // ------------------------------------------------------
            NuitrackForm formNuitrack = new NuitrackForm(this);
            formNuitrack.Close();

        }

Thank you for all the help you can give me.

Best regards.

Hi Pedro,

Please advise do you use Nuitrack.Init() and Nuitrack.Release() methods in the NuitrackForm constructor?

When and where in your code is the Nuitrack.Init() being called?

If init() is being called when the form opens.
Are you also calling Nuitrack.Release() when it is being closed.

Not calling release() can leave nuitrack is a confused state.

Furthermore - if you are using realsense sensors - there is also a potential issue that results in the sensor becoming locked even if you call Nuitrack,Release()

Westa

Hi!

Thanks for your answers.

I’m calling Nuitrack.Init() in the NuitrackForm constructor. Like this:

public NuitrackForm(Form1 form1)  //*** 
        {
            InitializeComponent();

            this.form1 = form1;  //***

            
            // Initialize Nuitrack. This should be called before using any Nuitrack module.
            // We pass default arguments. Thus, we specify that Nuitrack must determine
            // the location automatically.
            try
            {
                Nuitrack.Init("");
            }
            catch (nuitrack.Exception exception)
            {
                MessageBox.Show("Can not initialize Nuitrack. Exception: ", exception.ToString());
            }

...

And call the Nuitrack.Release() in the form closing event:

protected override void OnFormClosing(FormClosingEventArgs e)
        {
            // Release Nuitrack and remove all modules
            try
            {
                Nuitrack.Release();
            }
            catch (nuitrack.Exception exception)
            {
                Console.WriteLine("Nuitrack release failed. Exception: ", exception);
            }
        }

Also I’m using Orbbec Astra.