在DirectX中再次调用释放功能时会崩溃,这并非在所有计算机上都发生 [英] Release function is crashing when called again in directx, This is not happening on all machine

查看:89
本文介绍了在DirectX中再次调用释放功能时会崩溃,这并非在所有计算机上都发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

I have following code:

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"));
    }
}



这段代码在我的DLL中.

我在应用程序初始化时调用此方法



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); 



因为m_3d_device为NULL,所以将之称为
.
但是,当我调整应用程序大小时,我再次调用此函数以释放设备,然后创建新设备. (我这样做是因为调整大小后,画线时出现了问题,线看起来不清楚.)

对于所有PC客户端接受它来说,它的工作都很好,但是现在,该客户端已更改了grapic卡(类似于nvidia Quadro).问题是,在m_3d_device应用程序上调用release时会崩溃.



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.

推荐答案

没有崩溃"之类的东西.到底会发生什么,何时发生?捕获异常,转储异常信息,请确保您指出在哪行中引发了异常.你又是什么意思?当m_3d_device为NULL时,不调用发布;当然,当调用已发布的问题时,cab例外.
--SA
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


这篇关于在DirectX中再次调用释放功能时会崩溃,这并非在所有计算机上都发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆