Sign in to follow this  
smek2

DirectInput performance slow down in fullscreen

Recommended Posts

This is strange, my DirectX application is running smooth windowed, but running in fullscreen i encounter strange performance slow-downs of my directinput devices (mouse and keyboard). This happens every 10 or 20 seconds or so. Then all of a sudden the rate my keyboard and my mouse respond to my input will drop dramatically and i'll have to wait another couple of seconds. Then everything will be fine, until it drops down again. First i thought my application as a whole would slow down, but thats not the case. In fact all of the "graphic-stuff" renders as fast as ever during that strange freeze. Any suggestions? Thanks in advance.

Share this post


Link to post
Share on other sites
Hi there Smek,
How did you create your input device?

[Possible causes of slow/jerky input]
I am taking a while guess here, but you might be polling/creating your device each frame. It's hard to tell, could you please paste your code?

Share this post


Link to post
Share on other sites
My DirectInput class creates the devices like this:

void QInputDevice::Init()
{
// Create the DI object.
if(FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_pDInput, NULL)))
QEngine::Application.ErrorMsg("Could not initialize DirectInput");

if(FAILED(m_pDInput->CreateDevice(GUID_SysKeyboard, &m_pDInputKeyboard, NULL)))
QEngine::Application.ErrorMsg("Could not create DirectInput (keyboard)");

if(FAILED(m_pDInputKeyboard->SetDataFormat(&c_dfDIKeyboard)))
QEngine::Application.ErrorMsg("Could not set data format for DirectInput device (keyboard)");

if(FAILED(m_pDInputKeyboard->SetCooperativeLevel(QEngine::Application.GetWindowHandle(), DISCL_FOREGROUND | DISCL_EXCLUSIVE)))
QEngine::Application.ErrorMsg("Could not set cooperative level for DirectInput device (keyboard)");

if(FAILED(m_pDInputKeyboard->Acquire()))
QEngine::Application.ErrorMsg("Could not acquire DirectInput device (keyboard)");

//DangerMouse
if(FAILED(m_pDInput->CreateDevice(GUID_SysMouse, &m_pDInputMouse, NULL)))
QEngine::Application.ErrorMsg("Could not create DirectInput (mouse)");

if(FAILED(m_pDInputMouse->SetDataFormat(&c_dfDIMouse)))
QEngine::Application.ErrorMsg("Could not set data format for DirectInput device (mouse)");

if(FAILED(m_pDInputMouse->SetCooperativeLevel(QEngine::Application.GetWindowHandle(), DISCL_FOREGROUND | DISCL_EXCLUSIVE)))
QEngine::Application.ErrorMsg("Could not set cooperative level for DirectInput device (mouse)");

if(FAILED(m_pDInputMouse->Acquire()))
QEngine::Application.ErrorMsg("Could not acquire DirectInput device (mouse)");
}



I am not creating the devices every frame. However i call "GetDeviceState" every frame to check whether a key or mousebutton is pressed.
My applications main loop is calling the "InputUpdate()" routine of my DirectInput class and then continues to do the rest (like rendering lots of wildy rotating, sort of cute looking sprites).
The "InputUpdate" routines looks like this:
void QInputDevice::Update()
{
if (m_pDInputKeyboard->GetDeviceState(sizeof(UCHAR[256]), (LPVOID)KeyState)==DIERR_INPUTLOST)
{
if(FAILED(m_pDInputKeyboard->Acquire()))
Sleep(500);
}

if (m_pDInputMouse->GetDeviceState(sizeof(DIMOUSESTATE), &MouseState)==DIERR_INPUTLOST)
{
if(FAILED(m_pDInputMouse->Acquire()))
Sleep(500);
}
else
{
//get relative mouse coordinates and convert to absolute.
if ((m_lMouseX+MouseState.lX>=0)&&(m_lMouseX+MouseState.lX<QEngine::Application.GetWindowWidth()))
m_lMouseX+=MouseState.lX;
if ((m_lMouseY+MouseState.lY>=0)&&(m_lMouseY+MouseState.lY<QEngine::Application.GetWindowHeight()))
m_lMouseY+=MouseState.lY;
}
}


Also, i just realized that my windows explorer would not open any documents anymore. I could'nt even start "Notepad", instead i got a dialog telling me about some explorer.exe error. After restarting my machine everything seems to work fine again, no DirectInput freezes in my application either.
Maybe it wasnt really DirectInput related after all. Maybe it was just, well, Windows. Would'nt be the first time. :/

Share this post


Link to post
Share on other sites

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