data unacquired
I use DInput , I set foreground, so when DI lost focus it at data unacquired mode.
but my game can not go on, and totally stop ,show a white screen if DI at the mode.
why? how to fix? I look dx sample. it can automaticly acquire data if focus gained again.
Quote:Original post by Fallen God
I cant understand your questions, could you rephrase please?
for example I have a game that use DInput ,it run in windowed mode.
If you set SetCooperativeLevel to DISCL_FOREGROUND, that mean as soon as you lost focus on game you will unacquired data. if you set DISCL_BACKGROUND, you will always get data.
If you set DISCL_FOREGROUND and the game window is not active,dinpute will unacquire data and you again let game window active, it still can not acquire data, and it will stop running. like dead lock.
Quote:Original post by luasitdown
If you set DISCL_FOREGROUND and the game window is not active,dinpute will unacquire data and you again let game window active, it still can not acquire data, and it will stop running. like dead lock.
When your application regains focus, you have to call device->Aquire() again. This is how I do it:
// Get buffered dataif( FAILED( mKeyboard->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), diBuffer, &diElements, 0 ) ) ){ // Contact with the device has been lost LOG_INFO( "Keyboard Input Lost. Reacquiring..." ); // Reaquire the keyboard HRESULT hr = mKeyboard->Acquire(); while( hr == DIERR_INPUTLOST ) hr = mKeyboard->Acquire(); if( SUCCEEDED( hr ) ) { // The keyboard has been reaquired, try to get the input again LOG_SUCCESS( "Keyboard Reacquired" ); return UpdateKeyboard(); } else { // The application is most likely minimized LOG_FAILURE( "Keyboard Unacquired" ); return E_INPUTUNACQUIRED; }}
Quote:Original post by circlesoftQuote:Original post by luasitdown
If you set DISCL_FOREGROUND and the game window is not active,dinpute will unacquire data and you again let game window active, it still can not acquire data, and it will stop running. like dead lock.
When your application regains focus, you have to call device->Aquire() again. This is how I do it:// Get buffered dataif( FAILED( mKeyboard->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), diBuffer, &diElements, 0 ) ) ){ // Contact with the device has been lost LOG_INFO( "Keyboard Input Lost. Reacquiring..." ); // Reaquire the keyboard HRESULT hr = mKeyboard->Acquire(); while( hr == DIERR_INPUTLOST ) hr = mKeyboard->Acquire(); if( SUCCEEDED( hr ) ) { // The keyboard has been reaquired, try to get the input again LOG_SUCCESS( "Keyboard Reacquired" ); return UpdateKeyboard(); } else { // The application is most likely minimized LOG_FAILURE( "Keyboard Unacquired" ); return E_INPUTUNACQUIRED; }}
}HRESULT Di::Init(){ HRESULT hr; DWORD dwCoopFlags; dwCoopFlags = DISCL_FOREGROUND | DISCL_NONEXCLUSIVE; // Create a DInput object if( FAILED(hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&m_di, NULL ) )) return hr; // Obtain an interface to the system mouse device. if( FAILED(hr = m_di->CreateDevice( GUID_SysMouse, &m_mouse, NULL ) )) return hr; m_di->Release(); m_di = 0; if( FAILED(hr = m_mouse->SetDataFormat( &c_dfDIMouse2 ) )) return hr; HWND hwnd = m_device->hwnd(); if( FAILED(hr=m_mouse->SetCooperativeLevel( hwnd, dwCoopFlags ))) return hr; // Acquire the newly created device m_mouse->Acquire(); return hr;}DIMOUSESTATE2 & Di::mouseState(){ HRESULT hr; ZeroMemory(&m_dims2,sizeof(m_dims2)); while (FAILED(hr= m_mouse->GetDeviceState( sizeof(DIMOUSESTATE2), &m_dims2 ))) { hr = m_mouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = m_mouse->Acquire(); } return m_dims2;}
this is my code. but it not work.
One thing I wanna know ,even if dinput lost, why game dead? why it stop running?
This is from your code:
The problem is that you keep looping continuously, even after the device returns a failure code other than DIERR_INPUTLOST. If you look at my loop, when it fails again, I just return. This is because at this point, the application has probably been minimized and it may not be coming back any time soon. The app then goes into an idle processing loop, and comes back when focus is restored.
You prevent your application from doing this, because you just loop forever, even when it is trying to minimize. Your code is kind of similar to mine, but you need to look for the differences in it.
while (FAILED(hr= m_mouse->GetDeviceState( sizeof(DIMOUSESTATE2), &m_dims2 ))){hr = m_mouse->Acquire(); while( hr == DIERR_INPUTLOST ) hr = m_mouse->Acquire(); }
The problem is that you keep looping continuously, even after the device returns a failure code other than DIERR_INPUTLOST. If you look at my loop, when it fails again, I just return. This is because at this point, the application has probably been minimized and it may not be coming back any time soon. The app then goes into an idle processing loop, and comes back when focus is restored.
You prevent your application from doing this, because you just loop forever, even when it is trying to minimize. Your code is kind of similar to mine, but you need to look for the differences in it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement