none
Can not un-bind DLL RRS feed

  • Question

  • I'm using Unreal Development Kit and the only way to have any external code to run is to bind DLL's. I'v done so, and it works.  However, when trying to exit UDK, the DLL will not unbind and will crash.  I'm not sure what i'm doing wrong.

    Relevant DLL CODE

    #include <Windows.h>
    
    #include "MSR_NuiApi.h"
    #include "KinectTest.h"
    
    extern "C"
    {
    
    __declspec ( dllexport )KinectTest	*kinect;
    
    __declspec( dllexport ) bool InitKinect()
    {
    	kinect->Nui_Zero();
    	kinect->Nui_Init();
    
    	return true;
    }
    
    __declspec( dllexport ) float GetKinectX()
    {
    	//return (kinect->GetPosX() - .5) * 2;
    	return kinect->GetPosX();
    }
    
    __declspec( dllexport ) float GetKinectY()
    {
    	//return -(kinect->GetPosY() - .5) * 2;
    	return kinect->GetPosY();
    }
    
    __declspec ( dllexport ) BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved )
    {
    	switch( fdwReason )
    	{
    	case DLL_PROCESS_ATTACH:
    		kinect = new KinectTest();
    		InitKinect();
    		break;
    	
    	case DLL_PROCESS_DETACH:
    		kinect->Nui_UnInit();
    		delete kinect;
    		break;
    	}
    
    	return true;
    }
    
    } // extern"C"


    Relevant DLL CODE within the class

    HRESULT KinectTest::Nui_Init()
    {
    	//HRESULT hr;
    	int result;
    
    	//fx = 0;
    	//fy = 0;
    
    	m_hNextSkeletonEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
    
    	result = NuiInitialize( NUI_INITIALIZE_FLAG_USES_SKELETON );
    	result = NuiSkeletonTrackingEnable( m_hNextSkeletonEvent, 0 );
    
    	m_hEvNuiProcessStop = CreateEvent( NULL, FALSE, FALSE, NULL );
    	m_hThNuiProcess = CreateThread( NULL, 0, Nui_ProcessThread, this, 0, NULL );
    
    	return 0;
    }
    
    
    void KinectTest::Nui_UnInit()
    {
    	if( m_hEvNuiProcessStop != NULL )
    	{
    		SetEvent( m_hEvNuiProcessStop );
    
    		if( m_hThNuiProcess != NULL )
    		{
    			WaitForSingleObject( m_hThNuiProcess, INFINITE );
    			CloseHandle( m_hThNuiProcess );
    		}
    		CloseHandle( m_hEvNuiProcessStop );
    	}
    
    	NuiShutdown();
    
    	if( m_hNextSkeletonEvent && ( m_hNextSkeletonEvent != INVALID_HANDLE_VALUE ) )
    	{
    		CloseHandle( m_hNextSkeletonEvent );
    		m_hNextSkeletonEvent = NULL;
    	}
    }
    
    DWORD WINAPI KinectTest::Nui_ProcessThread( LPVOID pParam )
    {
    	KinectTest	*pthis = ( KinectTest * ) pParam;
    	HANDLE	hEvents[2];
    	int		nEventIdx;
    
    	hEvents[0]=pthis->m_hEvNuiProcessStop;
    	hEvents[1]=pthis->m_hNextSkeletonEvent;
    
    	while( 1 )
    	{
    		nEventIdx=WaitForMultipleObjects(sizeof(hEvents)/sizeof(hEvents[0]),hEvents,FALSE,100);
    
    		if( nEventIdx == 0 )
    			break;
    
    		switch( nEventIdx )
    		{
    		case 1:
    			pthis->Nui_GotSkeletonAlert();
    			break;
    		//case 2:
    		//	//
    		//	break;
    		//case 3:
    		//	//
    		//	break;
    		}
    	}
    	
    
    	return (0);
    }


    I tested by not initializing NUI, and the DLL works fine and gets closed properly.  The problem only happens when a call to NuiInitialize takes place.  To be clear, the DLL gets binded during gameplay and I can access the functions and use Kinect properly.  However, when I try to close the application, it crashes because it can't un-bind the DLL.  And this only happens when NuiInitialize is called, other it un-binds correctly.

    Any input is appreciated!  Sorry if I have left out any crucial component that might be of use to solve this problem.

     

    Wednesday, June 22, 2011 2:45 PM

Answers

  • We will investigate issue further. It seems like several people have run into this. Thanks for bringing it to our attention.
    I'm here to help
    Friday, September 30, 2011 1:10 AM

All replies

  • Have you tried running this under the debugger? Where exactly in the DLL_PROCESS_DETACH processing does it get stuck/crash?

    Eddy


    I'm here to help
    Monday, June 27, 2011 11:34 PM
  • We will investigate issue further. It seems like several people have run into this. Thanks for bringing it to our attention.
    I'm here to help
    Friday, September 30, 2011 1:10 AM