Sign in to follow this  
thuong

can not reset the direct3d device

Recommended Posts

thuong    100
Hi All, when my app run, in time i screen server, my app display error can not reset the direct3d device can anybody help me? thanks

Share this post


Link to post
Share on other sites
Dave Hunt    4872
When your device is lost you should call TestCooperativeLevel. When that returns D3DERR_DEVICENOTRESET, you can then call Reset. Note that you have to release your resources when the device is lost and restore them after the device is reset.

Share this post


Link to post
Share on other sites
thuong    100
thanks

my application is create window parent and render window child, window parent not use directx, window child use directx to render avatar. only error with this case.
when i create window render is windown parent then have not this error.

can you help me?

thanks

Share this post


Link to post
Share on other sites
Dave Hunt    4872
Could you post your lost device handling code and your device creation code? That might help me figure out what's going on.

Also, does this only happen when the screen saver kicks in, or does it also happen if you switch to another application and try to switch back?

Share this post


Link to post
Share on other sites
thuong    100
thanks

with screen server or click mouse right on the screen pc and select properties continue select setttings and change screen resolution and click ok then error occur.

my code:

if( m_bDeviceLost )
{
// Test the cooperative level to see if it's okay to render
if( FAILED( hr = m_pd3dDevice->TestCooperativeLevel() ) )
{
// If the device was lost, do not render until we get it back
if( D3DERR_DEVICELOST == hr )
return S_OK;

// Check if the device needs to be reset.
if( D3DERR_DEVICENOTRESET == hr )
{
// If we are windowed, read the desktop mode and use the same format for
// the back buffer
if( m_bWindowed )
{
D3DAdapterInfo* pAdapterInfo = m_d3dSettings.PAdapterInfo();
m_pD3D->GetAdapterDisplayMode( pAdapterInfo->AdapterOrdinal, &m_d3dSettings.Windowed_DisplayMode );
m_d3dpp.BackBufferFormat = m_d3dSettings.Windowed_DisplayMode.Format;
}

//MessageBox(NULL, "a", "a", MB_OK);

if( FAILED( hr = Reset3DEnvironment() ) )
return DisplayErrorMsg( D3DAPPERR_RESETFAILED, MSGERR_APPMUSTEXIT );
}
return hr;
}
m_bDeviceLost = false;
}

HRESULT Reset3DEnvironment()
{
// Reset the device
if( FAILED( hr = m_pd3dDevice->Reset( &m_d3dpp ) ) )
return hr;
}

can you help me?

Share this post


Link to post
Share on other sites
Dave Hunt    4872
Hmmm. I don't think it's a good idea to change your screen resolution while a DirectX application is running. That's not something that a user would normally do, and I don't think DirectX likes it, either. Does your screen saver also change screen resolution/color depth?

Share this post


Link to post
Share on other sites
thuong    100
thanks

yes, i see but i want test my app in all case. example when you run application and you go out to work anything on the time your pc automatic logout when you come back you must login when my app is error.

Share this post


Link to post
Share on other sites
Dave Hunt    4872
Ok. I think I'm wrong about the resolution change issue. You would get a D3DERR_DEVICELOST when the resolution is changed to give you an opportunity to reset things when you get control back.

Are you releasing all DirectX resources before trying to reset the device? If not, it won't let you reset. I don't know why that would be an issue for a child window, but not a top-level window, but stranger things have happened.

Share this post


Link to post
Share on other sites
Dave Hunt    4872
I don't know how to post an image. Sorry. Also, it's 3am and I have to work today. I'm going to bed. I'll check back when I can and try to help if someone else hasn't already gotten you taken care of.

Share this post


Link to post
Share on other sites
thuong    100
thanks

no, i do not release anything, i can not understand tranfer message in DirectX

my code:

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );
while( WM_QUIT != msg.message )
{
if( d3dApp.m_bActive )
d3dApp.m_bGotMsg = ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) != 0 );
else
d3dApp.m_bGotMsg = ( GetMessage( &msg, NULL, 0U, 0U ) != 0 );

if( d3dApp.m_bGotMsg )
{
// Translate and dispatch the message
if( hAccelTable == NULL || msg.hwnd == NULL ||
0 == TranslateAccelerator( msg.hwnd, hAccelTable, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
WaitMessage();
}


}
}

d3dApp is app use directx

Share this post


Link to post
Share on other sites
Dave Hunt    4872
Ok. I don't think the problem is in your WinMain function.

When I asked if you were releasing resources when the device is lost, you said you are not. A device reset will fail if you don't release the resources it is using first. Basically, unless your resources are created as D3DPOOL_MANAGED, then you need to release them on lost device and recreate them after reset. (That's an oversimplification, but a good rule of thumb.)

Share this post


Link to post
Share on other sites
yuhaobo    144
have you created any textures or surfaces using D3DPOOL_DEFAULT? u need to release them before u call d3dDevice->Reset(), and after the reset, re-create them.

Share this post


Link to post
Share on other sites
thuong    100
i do not create anything, i only create window and init directx, not draw anything.
i have parent window and child window(contain directx)
my app:

CMyD3DApplication d3dApp

d3dApp.Create(hInstance, parentWindow): create a child window with parent window is parameter: parentWindow.
in this create funcion i have Init3DEnvirontment.
d3dApp.Render();

My Example the same D3DFrameWork of samples of SDK(microsoft)

i only to interface to call it in the other app.

Share this post


Link to post
Share on other sites
mdias    823
1. Open your windows control panel
2. Double Click DirectX Icon
3. Click the Direct3D separator
4. Select Debug Runtime and click OK
5. Debug your aplication and see it's output

Share this post


Link to post
Share on other sites
thuong    100
i debug it have error following:

Reset can only be called from the thread that the device was created from.

can you help me explain clearly it and help me find a way to fix it?

thanks

Share this post


Link to post
Share on other sites
thuong    100
it have a warning:

Device that was created without D3DCREATE_MULTITHREADED is being used by a thread other than the creation thread.

thanks

Share this post


Link to post
Share on other sites
yuhaobo    144
arh...there

the error means u called pd3d->CreateDevice() in one thread, but u called pd3dDevice->Reset() in another thread. This is not acceptable to DirectX even if u have the multi-thread flag set.

U have to re-structure your program to have all the directX drawing stuff in one thread.

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