Leap Listener controller stops working after some time in VS2012

天涯浪子 提交于 2019-12-11 19:32:54

问题


We have integrated flash game (crazytaxi.swf) inside Windows form application in VS Express 2012 for Windows Desktop.We are controlling game with the help of gestures using leapmotion controller.

What happens is when we run project in VS2012,game starts normally.We play game using gesture (left,right etc.).But after some time controller stops listening by exiting its thread.We can see that in output window. "The thread '' (0x1b50) has exited with code 0 (0x0)." this we get in output window.

We are not getting how to overcome this challenge.


回答1:


You didn't provide enough information but from what I gather, your LEAP thread ran to completion and closed. This can occur if you declare and initialize your listener and controller variables in a function and the variables go out of scope when the function is executed. This causes Garbage Collector to dispose both controller and listener at what might seemingly appear as random (non reproductable) moments. To fix this issue, create a singleton for the controller and listener - this can boil down to simply defining a static controller and listener variables in some class. This way the listener and controller objects will never go out of scope and get disposed by the GC.




回答2:


"The thread '' (0x1b50) has exited with code 0 (0x0) basically says that:

The thread with the ID 6992 ran and completed the operation successfully.

System Error Codes (0-499)

The question is, does the device stop tracking?

Here are my 0x0's from my Leap Motion app (its working fine):

The thread 'vshost.NotifyLoad' (0x364) has exited with code 0 (0x0). The thread '' (0x3348) has exited with code 0 (0x0). The thread 'vshost.LoadReference' (0x37c8) has exited with code 0 (0x0).

Also, on a side note, because it has nothing to do with the error code - are you removing the listener from the controller, and then disposing of them both when the application is being closed? Not properly disposing of objects will cause problems.

A second note - onExit and onDisconnet are two different things.

onDisconnect(controller:Controller):void Called when the Controller object disconnects from the Leap Motion software. Listener

onExit(controller:Controller):void Called when this Listener object is removed from the Controller or the Controller instance is destroyed.

In case somebody is having similar problems here is the reply I sent over email after having a look at the code:

I've looked at the code, since you only sent me a few files I had to comment out the the references to classes that was not included in the zip.

The code runs fine with 3 different Leap Motion devices - when I comment out from the method, what I suggest is:

  1. Update the SDK. I used .Net 4 dll and the latest version of the SDK which today is: v.1.0.8.7665

  2. Dispose the objects once you are done using them. Dispose Frames after using them, Remove listener from the Controller, and dispose Controller when the device isn't used anymore or the application is being closed.

  3. I noticed some Timers and DispatcherTimers they were being created, but I couldn't find any references to where they were being used. What are these being used for? DispatcherTimer doesn't belong in a windows forms application.

My best guess - and I hate to guess - is that there is a threading problem OR that the objects aren't being disposed correctly - OR you are using an SDK version that had bugs.

I have two applications on GitHub - feel free to use the code as you want. There is one for WPF and one for Windows Forms - both need to be updated for latest SDK as some things have been deprecated (such as the Screen class) in later versions of the SDK.

WPF: https://github.com/IrisClasson/Leap-Motion

Windows Forms: https://github.com/IrisClasson/LeapMotion_WinForms_Demo_OLD_SDK

Disclaimer: I don't do much, if any WinForms development




回答3:


I had a same issue with my WPF application and Leap Motion code but the code works fine with a console application.

In WPF when I globally declared the Leap-Listener and the controller Object, I did not face the error any more and the Listener is active all time.

Just declare the listener and controller in the class (globally) from which you call the listener

public static LeapListener listener;

public static Controller controller;

Now use this listener object, and add it to the controller and enable gesture property of the controller in a function or a constructor.

listener = new LeapListener();
controller.AddListener(listener);
controller = new Controller();

This should solve the issue. If the problem still persists (detection problem), simply initialize and add the same listener object to the controller object onExit event. Now the gesture and other properties exist as you are not creating a new instance of the controller again.



来源:https://stackoverflow.com/questions/18585843/leap-listener-controller-stops-working-after-some-time-in-vs2012

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!