Page 2 of 7
Re: Game (unity3d) with phidgets hangs on close
Posted: Thu Nov 04, 2010 10:32 am
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
Re: Game (unity3d) with phidgets hangs on close
Posted: Fri Nov 05, 2010 1:40 am
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
Re: Game (unity3d) with phidgets hangs on close
Posted: Fri Nov 05, 2010 10:08 am
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
Re: Game (unity3d) with phidgets hangs on close
Posted: Fri Nov 05, 2010 10:53 am
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
Re: Game (unity3d) with phidgets hangs on close
Posted: Sun Nov 14, 2010 5:24 am
by seriousmedia
Is there a way to debug what's happening?
Re: Game (unity3d) with phidgets hangs on close
Posted: Tue Dec 14, 2010 3:30 am
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?
Re: Game (unity3d) with phidgets hangs on close
Posted: Tue Dec 14, 2010 10:16 am
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
Re: Game (unity3d) with phidgets hangs on close
Posted: Tue Dec 14, 2010 1:37 pm
by seriousmedia
not calling close does not make a difference, unfortunately.
Re: Game (unity3d) with phidgets hangs on close
Posted: Wed Dec 22, 2010 2:50 am
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
Re: Game (unity3d) with phidgets hangs on close
Posted: Wed Dec 22, 2010 10:08 am
by Patrick
What if you don't register any even handlers? Also, what type of Object owns the Phidget object?
-Patrick