Game (unity3d) with phidgets hangs on close

Supporting Visual Studio on Windows
Post Reply
seriousmedia

Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

hello,
Im programming a game in unity3d that uses 3 steeringwheels connected to a ik888. It works great, but when i try to close the game it hangs.
I have, of course, tried without the phidgets code and then it closes fine.
I use the phidgets21.net.dll in c#.
I attach the ik888 and connect to a dictionary (and start a key listener).
Everything gets closed before the game actually quits, but still it hangs.

Can anyone help me with this?

Ramon
erik
King of the Lab
Posts: 476
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: Game (unity3d) with phidgets hangs on close

Post by erik »

After you close the phidgets, try inserting

Code: Select all

Application.DoEvents();
There might be event messages still in queue for the phidgets even after you've closed them.
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

Thanks,

but there is no Application.DoEvents() in unity3d.
But i wait (using Invoke see:http://unity3d.com/support/documentatio ... nvoke.html) a second before quitting the application.

I don't know if this should have the same effect as the DoEvents in .NET.

Ramon
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

I've tried a different approach (Coroutines with yield to simulate DoEvents in unity3d). But that still doesn't solve the problem.

The game still hangs while closing the phidgets.
I've attached errorEventHandlers to all the objects, but they don't fire an Error event.
I've also attached a ServerDisconnect event handler. But this one is never fired.
Is this supposed to fire on close?

greetings,

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 »

Do you remove all event handlers before calling close?

-Patrick
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

Yes,
All event handlers are removed before closing.
Is there any way to test/debug this?

Ramon
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

Anyone??
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 »

If you post your code, I can probably debug it. It's hard to say what could be going on without the code.

-Patrick
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

I've created a simple test using the phidget in unity3d with the phidget21.net.dll and it works fine. Closing the test-app is no problem.
I must be doing something weird in my game.
I'll look into the code.
Thanks for the help!

greetings,

Ramon
seriousmedia

Re: Game (unity3d) with phidgets hangs on close

Post by seriousmedia »

Hello again,

i'm afraid the problem is not solved yet.
I can close the game in the IDE about 4 times before Unity3D crashes.
When i publish the game i cannot close it without crashing.

Here's my code
- base code -------------------

Code: Select all

using UnityEngine; 
using System.Collections; 
using System; 


public class testscript : MonoBehaviour
{

   private Phidget_script phid;
   public bool okToQuit = false;
	
	void Awake ()
   {
	phid = GetComponent<Phidget_script>();
   } 
   
   void Start()
  {
	Debug.Log("Connecting to phidgets");
	phid.connect("localhost","5001");
  }
  

 void OnApplicationQuit () 
   {
	 Debug.Log("OnApplicationQuit() called."); 
	 if (okToQuit==false) { 
		Debug.Log("Cancel quitting");
		Application.CancelQuit(); 
		phid.close();
	} 
   }
   
   public void complete_close() 
   {
		Debug.Log("testscript Complete Close");
	   okToQuit=true;
	   Application.Quit();
   }
 
}
- phidget script -----------

Code: Select all

using System;
using System.Collections;
using System.Text;


using Phidgets;
using Phidgets.Events;  

using UnityEngine;

    public class Phidget_script: MonoBehaviour
    {
        InterfaceKit ifKit;
		
		private string phidget_adres;
		private int phidget_port;
		
        public void connect(string phidgetadres,string phidgetport)
        {
			Debug.Log("interfaceKit Program connect : "+ phidgetadres + " / " + phidgetport);
			phidget_adres = phidgetadres;
			phidget_port = Convert.ToInt32(phidgetport);

            try
            {
				Debug.Log("Initialize the InterfaceKit object");
				ifKit = new InterfaceKit();

				ifKit.Attach += new AttachEventHandler(ifKit_Attach);
				ifKit.open(phidget_adres,phidget_port);
            }
            catch (PhidgetException ex)
            {
                Debug.Log("InterfaceKit Program connect exception: "+ex.Description);
            }
			
        }

        void ifKit_Attach(object sender, AttachEventArgs e)
        {
            Debug.Log("InterfaceKit attached!"+e.Device.SerialNumber.ToString());
        }
		
		
		
		public void close() {
			StartCoroutine(closeEnum());
		}
		
		
   private IEnumerator closeEnum () {     

		yield return StartCoroutine(WaitFunction (0.5f));        
		close_ifkit1();
		yield return StartCoroutine(WaitFunction (1f));        
		close_ifkit2();
		yield return StartCoroutine(WaitFunction (1f));        
		SendMessage("complete_close");
	
	}

		private void close_ifkit1() {
				
			Debug.Log("close ifkit1");
			if (ifKit!=null) {
				ifKit.Attach -= new AttachEventHandler(ifKit_Attach);
			}

		}
		
		private void close_ifkit2() {
	
			if (ifKit!=null) {
				Debug.Log("close ifkit2");
				ifKit.close();
				Debug.Log("after ifKit.close");
				ifKit = null;
			}

		}

    IEnumerator WaitFunction (float delay) {       
		float timer = Time.time + delay;        
		while (Time.time < timer) {            
			yield return null;        
			}   
	}
}
i'm i doing something wrong?
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests