Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 386837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:36:53+00:00 2026-05-12T15:36:53+00:00

An interesting bug came up that I’m having no luck with. In a windowed

  • 0

An interesting bug came up that I’m having no luck with. In a windowed Direct3D9 program using native code, I handle a device lost using something similar to the following:

void MyClass::RecoverFromDeviceLost(LPDIRECT3DDEVICE9 deviceToRecover, D3DPRESENT_PARAMETERS devicePresentParams )
{


    HRESULT hr = deviceToRecover->TestCooperativeLevel();
    if(hr == D3DERR_DEVICELOST ) { 
        //Code to shutdown all D3DPOOL_DEFAULT allocated objects

    }else if(hr == D3DERR_DEVICENOTRESET){

        hr = deviceToRecover->Reset(&devicePresentParams);
        if(SUCCEEDED(hr))
        {
            //Code to rebuild all D3DPOOL_DEFAULT objects

        }

    }

}

This works fine on Vista, but seems to have major problems on XP. If the monitor is unplugged, or switched away from the PC via a KVM, I never receive the D3DERR_DEVICELOST. The only return value from TestCooperativeLevel I ever receive is D3DERR_DEVICENOTRESET. And every call to Reset gives a D3DERR_INVALIDCALL. I tried forcing the program to use the shutdown code by doing this:

...
else if(hr == D3DERR_DEVICENOTRESET){

        hr = deviceToRecover->Reset(&devicePresentParams);
        if(SUCCEEDED(hr))
        {
            //Code to rebuild all D3DPOOL_DEFAULT objects

        }else {
            //Duplicate of code to shutdown all D3DPOOL_DEFAULT objects
        }

    }
...

But there was no change. This problem only seems to affect Windows XP (so far tested on SP2, SP3). I am using the August 2007 DXSDK, and can’t update at this time. Has anyone seen this problem before, or have any idea why I can’t reset my device?

UPDATE: I believe I have found a solution, but am still perplexed by the failure of the second code segment listed above. After getting the DirectX Debug runtime to work over remote debugging, I realized the reason that the Reset function kept failing was because there were unreleased resources. However, the exact same release code, when applied as shown in the answer, resolved the issue. I did verify that the program was not creating D3DPOOL_DEFAULT objects between calls to the recover function. Is there something in the structure of Direct3D that could cause a problem if performing a reset as shown in the this question’s code segments?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:36:54+00:00Added an answer on May 12, 2026 at 3:36 pm

    I ended up testing a different program that uses DirectX for graphics, just to see if the problem was just with the one program. The other application recovered with no problems from a monitor unplug or KVM switchover in Windows XP. The main difference between the two programs was that the working one used DXUT to manage the Direct3d, whereas I was doing all manual management in the one that didn’t work. After combing through the DXUT source code, I noticed that they used a single step approach to device recovery that didn’t rely on a D3DERR_DEVICELOST being returned from TestCooperativeLevel prior to the D3DERR_DEVICENOTRESET return value. The following code seems to have fixed the problem:

    void MyClass::RecoverFromDeviceLost(LPDIRECT3DDEVICE9 deviceToRecover, D3DPRESENT_PARAMETERS devicePresentParams )
    {
    
        HRESULT hr = deviceToRecover->TestCooperativeLevel();
        if(hr == D3DERR_DEVICELOST ) { 
            //Device is lost and cannot be reset yet
            return;
        }
    
    
        //Code to shutdown all D3DPOOL_DEFAULT allocated objects
    
        hr=deviceToRecover->Reset(&devicePresentParams);
        if(SUCCEEDED(hr)){
    
            //Code to rebuild all D3DPOOL_DEFAULT objects
    
        }
    }
    

    This code does have the side effect of resetting multiple times if the monitor is unplugged (or KVM switched) for an extended period of time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An interesting issue came up recently. We came across some code that is using
I came across an odd bug in my code that revealed an interesting behavior
I found an interesting bug in a program that I implemented somewhat lazily, and
Interesting bug or side effect or something... using will_paginate to handle the pagination of
This code has an interesting bug: some_struct struct_array1[10] = {0}; some_struct struct_array2[10] = {0}
So I just fixed an interesting bug in the following code, but I'm not
I have run into an interesting bug where it appears that when you select
I am having an interesting bug in MSIE8, only. I have also tested this
I have come across an interesting code example that allows me to make DIV
I've run into an interesting issue that I'm afraid might be a bug with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.