Game (unity3d) with phidgets hangs on close

Supporting Visual Studio on Windows
Post Reply
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Game (unity3d) with phidgets hangs on close

Post by Patrick »

I there a good reason for the convoluted closing routine? Is this the actual code that causes problems? I could see you having some issues with the close hanging if you were using a sensor change handler, but you're not, so...

-Patrick
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

I did the closing this way to give the phidgets enough time to close (i read in the forum something about using Application.DoEvents() when having problems with closing, but unity3D does not support Application.DoEvents() and coroutines are advised to be used).

But i tried a very straightforward:
ifKit.close();
ifKit = null;

That didn't make any difference though.

Ramon
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Game (unity3d) with phidgets hangs on close

Post by Patrick »

Application.DoEvents() is only needed for some fairly specific cases. It has to do with Phidgets events. Since the events are coming in on a seperate thread, they will invoke their event handlers in the context of their owning object if invokeRequired is true. Because close is called in the GUI example in the same context as the invoked events (ie sensor change event), there may be a pending sensor change event while the formClosed event is running. Therefore if we call close, we get a deadlock -> close will not return until the sensorChange event returns from its invoke, but the sensorChange event won't get invoked until after formClosed returns.

So, we de-register the event, call Application.DoEvents() to make the sensorChange event run right now, then call close.

I doubt this is the problem you're having, as you aren't using the sensorChange event, and the attach event is not likely causing issues - unless you happen to attach the Phidget right as you are closing the program.

If you are using sensorChange events - which really is the only thing I can think of that would cause your issue, then you need to look at what you event is doing, and whether it is being invoked or not.

-Patrick
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

Normally i use the sensorChange event in the game, but as a test i just attach to the phidget (see the code) and nothing else.

Ramon
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

Is there a way to debug what's happening?
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

I've tried installing the latest version of unity3d with the latest phidget-drivers today and still no luck.
Strange thing is that when running in IDE-mode (run inside the development interface) closing is not a problem. Only when running the published .exe file.
Also when i just create the 'interfaceKit' object and attach an event-handler (attachEventHandler for example) and then don't call the open method, everything closes fine.

Anyone know what to test next?
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Game (unity3d) with phidgets hangs on close

Post by Patrick »

What happens if you don't call close? It may not be necessary in your case - you really only need to worry about it if you want to close and then open multiple times in one program run. The Phidgets will be released when the program exits. Also, close is called and the handle is cleaned up in the class finalize method which gets called from garbage collection.

-Patrick
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

not calling close does not make a difference, unfortunately.
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

When running the simpified version (just connecting to the phidget) in the unity3D IDE, it closes fine and connects fine the following times.
Just when i publish the unity3D and then run it, i can't close it without hanging.

edit: When closing the Unity3D IDE it hangs :-(
User avatar
Patrick
Lead Developer
Posts: 3399
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Game (unity3d) with phidgets hangs on close

Post by Patrick »

What if you don't register any even handlers? Also, what type of Object owns the Phidget object?

-Patrick
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests