DirectX - Error when pressing ctrl + alt + del

So far my program is working pretty well. Unfortunately when I press ctrl + alt + del it throws an error. Now I have read this question:

E_ACCESSDENED when using ctrl alt del

In which it is mentioned that the computer switches to a different screen (in which you don't have any writing permissions). It's just that I have no idea how to trace if I have writing permission in the current screen.

My code looks like:

void D3D::StartFrame() {
    HRESULT result;

    result = pDevice->Clear( 0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(FRAME_BG_R,FRAME_BG_G,FRAME_BG_B),0.0f,0 );
    assert( !FAILED( result ) );

    result = pBackBuffer->LockRect( &backRect,NULL,NULL );
    assert( !FAILED( result ) );

void D3D::EndFrame() {
    HRESULT result;

    result = pBackBuffer->UnlockRect();
    assert( !FAILED( result ) );

    result = pDevice->Present( NULL,NULL,NULL,NULL );
    assert( !FAILED( result ) );

Currently I am running the "StartFrame()" function each frame followed by some actions that should be done during the frame. At the end it will call the "EndFrame()" function that will unlock the drawing rectangle.

Now the error that occurs comes from the last assert (the StartFrame() assert doesn't fail?). Should I change these functions to return booleans telling the program if it should continue or not? Should I make it stop the entire program (which feels a bit odd)? Perhaps I am handling the rectangle locking the wrong way (should it work with asserts)?

Error: Assertion failed! - !FAILED(result)

Any help/advice would be appriciated !


First of all, whenever you get an error, before doing somethig, and before even thinking about what happened, you must check what exactly error message said.

In case of DirectX 9, you must not only check if HRESULT variable FAILED but get detailed info from it. You can get details from it using DXGetErrorString() and/or DXGetErrorDescription() functions (dxerr.h + dxerr.lib). For example, you can handle you errors by writing a small helper function, that accepts HRESULT and shows MessageBox() with details if it FAILED. Also, there is a good DXTrace() macro as a quick solution. Or, as a quickest lazy solution, you can just set a breakpoint right after function fail, and inspect value of HRESULT variable in debug watcher.

In your case, because we don't have error description in your post, we can only guess what happened (that's what guys from SO doesn't like the most). And I suspect here Device Lost state. That state sometimes happens when your app looses focus (Alt+tab, Ctrl+Alt+Del, etc.). To prevent crashes you must handle such exceptional states as described on MSDN or this short tutorial.

Of course, my guess can be wrong here, because I dont't know, what exactly happened. Please add proper error handling and provide additional information to get concrete help.

Happy coding!

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.