|
Direct3D\Tutorials的代码中,d3d9 对象是最后才Release()掉
《DirectX 9.0 3D游戏开发编程基础》的源代码中在InitD3D()函数的最后就release()掉了。
Tutorials中的
------------------------------------------------------------------------------------
LPDIRECT3D9 g_pD3D = NULL; /// 创建D3D 设备的D3D对象参数
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; /// 渲染中使用的D3D设备
。
。
。
。
VOID Cleanup()
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if( g_pD3D != NULL)
g_pD3D->Release();
}
。
。
。
--------------------------------------------------------------------------------------
《DirectX 9.0 3D游戏开发编程基础》的源代码中
--------------------------------------------------------------------------------------
bool d3d::InitD3D(HINSTANCE hInstance,int width, int height,bool windowed,D3DDEVTYPE deviceType,IDirect3DDevice9** device)
{
//
// Create the main application window.
//
。
。
。
//
// Init D3D:
//
HRESULT hr = 0;
// Step 1: Create the IDirect3D9 object.
IDirect3D9* d3d9 = 0;
d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
if( !d3d9 )
{
::MessageBox(0, "Direct3DCreate9() - FAILED", 0, 0);
return false;
}
// Step 2: Check for hardware vp.
//...
// Step 3: Fill out the D3DPRESENT_PARAMETERS structure.
D3DPRESENT_PARAMETERS d3dpp;
//...
// Step 4: Create the device.
hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, deviceType, hwnd, vp, &d3dpp,device);
if( FAILED(hr) )
{
d3d9->Release(); // done with d3d9 object
::MessageBox(0, "CreateDevice() - FAILED", 0, 0);
return false;
}
d3d9->Release(); // done with d3d9 object
return true;
}
------------------------------------------------------------------------
上面可见,d3d9->CreateDevice(...)后,就d3d9->Release()了。记得有些书上说,应该最后才释放d3d9对象的。希望高人解答。 |
|