none
Kinect C++ DLL for Unity RRS feed

  • Question

  • Hello,

    I successfully created a custom C++ DLL which uses Microsoft SDK Kinect 1.7 then imported into Unity. I have image stream, hand interactions, skeleton and all working in Unity. However, each time I stop Unity from previewing, it freezes and I have to end process of Unity then restart the project all over again. It's like Unity won't release or unload the DLL. I wrote a shutdown function in C++ for Unity to call too. Has anyone tried this themselves and had any luck?


    • Edited by Goss84 Monday, April 15, 2013 6:39 PM
    Monday, April 15, 2013 6:26 PM

Answers

  • Here my shutdown code in C++

    // Start the Nui processing thread
    m_hEvNuiProcessStop = CreateEvent(nullptr, TRUE, FALSE, nullptr);
    m_hThNuiProcess = CreateThread(nullptr, 0, NuiProcessThread, this, 0, nullptr);

    void KinectManager::ShutdownKinect()
    {
    	//Stop the Nui processing thread
    	if(m_hEvNuiProcessStop != nullptr)
    	{
    		//Signal the thread to stop
    		bool eventSet = SetEvent(m_hEvNuiProcessStop);
    
    		//Wait for thread to stop
    		if(m_hThNuiProcess != nullptr)
    		{
    			WaitForSingleObject(m_hThNuiProcess, INFINITE);
    			CloseHandle(m_hThNuiProcess);
    		}
    		CloseHandle(m_hEvNuiProcessStop);
    	}
    
    	sensor->NuiShutdown();
    	sensor->Release();
    
    	if(m_pDepthManager != nullptr)		 m_pDepthManager->~DepthManager();
    	if(m_pImageManager != nullptr)		 m_pImageManager->~ImageManager();
    	if(m_pSkeletonManager != nullptr)	 m_pSkeletonManager->~SkeletonManager();
    	if(m_pInteractionManager != nullptr) m_pInteractionManager->~InteractionManager();
    
    	delete this;
    }
    It gets stuck at 
    WaitForSingleObject(m_hThNuiProcess, INFINITE); 
    because I pass the INFINITE parameter. But if I pass a non infinite then I get a stack overflow error in Unity.


    Monday, April 15, 2013 7:17 PM

All replies

  • Here my shutdown code in C++

    // Start the Nui processing thread
    m_hEvNuiProcessStop = CreateEvent(nullptr, TRUE, FALSE, nullptr);
    m_hThNuiProcess = CreateThread(nullptr, 0, NuiProcessThread, this, 0, nullptr);

    void KinectManager::ShutdownKinect()
    {
    	//Stop the Nui processing thread
    	if(m_hEvNuiProcessStop != nullptr)
    	{
    		//Signal the thread to stop
    		bool eventSet = SetEvent(m_hEvNuiProcessStop);
    
    		//Wait for thread to stop
    		if(m_hThNuiProcess != nullptr)
    		{
    			WaitForSingleObject(m_hThNuiProcess, INFINITE);
    			CloseHandle(m_hThNuiProcess);
    		}
    		CloseHandle(m_hEvNuiProcessStop);
    	}
    
    	sensor->NuiShutdown();
    	sensor->Release();
    
    	if(m_pDepthManager != nullptr)		 m_pDepthManager->~DepthManager();
    	if(m_pImageManager != nullptr)		 m_pImageManager->~ImageManager();
    	if(m_pSkeletonManager != nullptr)	 m_pSkeletonManager->~SkeletonManager();
    	if(m_pInteractionManager != nullptr) m_pInteractionManager->~InteractionManager();
    
    	delete this;
    }
    It gets stuck at 
    WaitForSingleObject(m_hThNuiProcess, INFINITE); 
    because I pass the INFINITE parameter. But if I pass a non infinite then I get a stack overflow error in Unity.


    Monday, April 15, 2013 7:17 PM
  • OT: any chance for sharing this dll?
    Monday, April 15, 2013 7:18 PM
  • Unfortunately I can't right now. Otherwise, I wouldn't mind. 
    Monday, April 15, 2013 7:28 PM