Click here to Skip to main content
15,886,751 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have following code:

C++
void CD3DXGraph::InitializeDevice(
    const HWND &f_hwnd,
    const CRect &f_rect
) {
    try {


    D3DPRESENT_PARAMETERS l_d3dpp;

    //function gets direct3d pointer.
    if(NULL == m_d3d) {
        m_d3d = Direct3DCreate9(D3D_SDK_VERSION);
        if(NULL == m_d3d) {
            return;
        }
    }

    //fills D3dPresent parameters.
    //Backbuffer width is same as dialog area.
    ZeroMemory(&l_d3dpp, sizeof(l_d3dpp));
    l_d3dpp.Windowed = true;
    l_d3dpp.hDeviceWindow = f_hwnd;
    l_d3dpp.BackBufferCount = 1;
    l_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    l_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    l_d3dpp.BackBufferWidth = f_rect.Width();
    l_d3dpp.BackBufferHeight = f_rect.Height();

    //sets frame rect
    SetFrameRect(f_rect);

    //store the handle to use during lost device case.
    m_graph_hwnd = f_hwnd;

    if (NULL != m_d3d)
    {
        //Release device if already exist
        if (NULL != m_3d_device)
        {
            HRESULT  hret = m_3d_device->TestCooperativeLevel();
            if (hret == D3DERR_DEVICELOST || hret == D3DERR_DEVICENOTRESET || hret == D3DERR_DRIVERINTERNALERROR)
            {
                AfxMessageBox("CD3DXGraph::InitializeDevice TestCooperativeLevel -> Error");
            }

            m_3d_device->Release();
            m_3d_device = NULL;


        }
        //Create device
        HRESULT device_creation_state =
        m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
            f_hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &l_d3dpp,
            &m_3d_device);
    }
    } catch (...) {
        AfxMessageBox(_T("catch CD3DXGraph::InitializeDevice"));
    }
}


This code is in my DLL.

I call this method when application is initialized

m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,f_hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &l_d3dpp,
&m_3d_device); 


this is called since m_3d_device is NULL.

But when i resize the application then i call this function again to release the device then create new device. (I did this because after resize there was a problem in line drawing lines were looking unclear.)

This was working fine for all the PC client had accepted it, but now the client has changed their grapic card (something like a nvidia quadro). The problem is that when release is called on m_3d_device application is crashing.
Posted
Updated 8-Feb-11 1:40am
v3

1 solution

There is no such thing as "crashing". What exactly happens and when? Catch exception, dump exception information, make sure you indicate in what line(s) exception is thrown. What do you mean "again"? Release is not called when m_3d_device is NULL; when it's called on already released problem, cab be exception, of course.
--SA
 
Share this answer
 
Comments
lilesh 11-Feb-11 1:56am    
i will explain in detail.

m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,f_hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE,
&l_d3dpp,m_3d_device);

is called 1st time when application initialise 1st time, that time
release is not called i.e. m_3d_device->Release() this is not called.

But when application is resize i call same method to release the
device and Create device again so that my graph will be seen
properly.(if i don't do this then graph drawn looks blur , because
device previously made is not with the same resolution, when we resize
the application. )

Now when application resize same function is called and
m_3d_device->Release()throws exception.

Some how reference count is getting 0. Temporary solution i have found .
1. comment m_3d_device->Release() line
2. Or add ref m_3d_device->AddRef before m_3d_device->Release() this
solves the problem but there is memory leak in the applicaion. just
want to mention again, this problem is not happening on all machine.
It is happening only on graphics card whose details are as follows
Card name: NVIDIA Quadro FX 580
Manufacturer: NVIDIA
Chip type: Quadro FX 580

Plz let me know wht can i don more.. it's very urgent.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900