gpt4 book ai didi

c++ - HRESULT 0x8876086c D3DERR_INVALIDCALL with DirectX9 几乎遵循文档示例

转载 作者:行者123 更新时间:2023-12-05 02:45:40 25 4
gpt4 key购买 nike

所以我想在另一个窗口上绘制一个覆盖图,但是我没有得到真正的运行时错误,visual Studio 调试工具告诉我

HRESULT res = object->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWND, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, NULL, &device);

是 0x8876086c。所以这里是我的代码片段,它们很重要并导致此错误 (D3DERR_INVALIDCALL),这导致设备成为空指针,这意味着我无法对其执行任何操作。

我真的不明白是什么导致了这种情况,因为我几乎是按照文档做的

int Paint::init(HWND hWND) {
if (FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &object))) {
exit(1);
}
ZeroMemory(&params, sizeof(params));

params.BackBufferWidth = width;
params.BackBufferHeight = height;
params.Windowed = true;
params.hDeviceWindow = hWND;
params.MultiSampleQuality = D3DMULTISAMPLE_NONE;
params.BackBufferFormat = D3DFMT_A8R8G8B8;
params.EnableAutoDepthStencil = TRUE;
params.AutoDepthStencilFormat = D3DFMT_D16;


HRESULT res = object->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWND, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, NULL, &device);

在头文件中:

class Paint {
private:
IDirect3D9Ex* object = NULL;
IDirect3DDevice9Ex* device = NULL;
DWORD behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;

D3DPRESENT_PARAMETERS params;
ID3DXFont* font = 0;
HWND TargetHWND;
int width, height;

int init(HWND(hWND));
}

最佳答案

D3DPRESENT_PARAMETERS params = {};

// Use Win32 BOOL "TRUE" instead of C++ "true"
params.Windowed = TRUE;
params.hDeviceWindow = m_window;

// params.BackBufferWidth, BackBufferHeight are ignored for Windowed = TRUE

// For Windowed = TRUE, use params.BackBufferFormat = D3DFMT_UNKNOWN, which is zero.

// For params.BackBufferCount zero is assumed to be 1, but best practice
// would be to set it
params.BackBufferCount = 1;

// You used D3DMULTISAMPLE_NONE for the MultiSampleQuality instead of MultiSampleType.
// It's all zero anyhow.

params.EnableAutoDepthStencil = TRUE;
params.AutoDepthStencilFormat = D3DFMT_D16;

// --->>> This is the actual bug: there is no valid SwapEffect that has a value of zero <<<---
params.SwapEffect = D3DSWAPEFFECT_DISCARD;

您假设 Direct3D9 设备支持 D3DCREATE_HARDWARE_VERTEXPROCESSING,但您尚未验证它是否真的支持它。也就是说,D3DCREATE_SOFTWARE_VERTEXPROCESSING 在 Windows 10 上存在已知性能问题,因此无论如何您可能只需要 HW。

You should not be using legacy Direct3D9 or Direct3D9Ex for new projects. It's mostly emulated on newer versions of Windows, has lots of strange behaviors, and is almost 20 years old at this point. There's no support for the Direct3D 9 debug device on Windows 8.x or Windows 10. You should consider Direct3D 11 as a much better starting place for developers new to DirectX.

关于c++ - HRESULT 0x8876086c D3DERR_INVALIDCALL with DirectX9 几乎遵循文档示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65835578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com