Sign in to follow this  

data unacquired

This topic is 4335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 data
if( 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;
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by circlesoft
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 data
if( 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?

Share this post


Link to post
Share on other sites
This is from your code:

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.

Share this post


Link to post
Share on other sites
the key is:
when program minimize, will it return other error,including DIERR_INPUTLOST ?

more, as soon as program regain focus, must I use UpdateKeyboard() ?

what is UpdateKeyboard() ?

Share this post


Link to post
Share on other sites

This topic is 4335 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this