c++ HRESULT 0x8876086c D3DERR_INVALIDCALL与DirectX9基本上遵循文档示例

8ehkhllq  于 2023-03-05  发布在  其他
关注(0)|答案(2)|浏览(239)

所以我想在另一个窗口上绘制一个覆盖图,但是我没有得到真实的的运行时错误,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));
}
zhte4eai

zhte4eai1#

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上存在已知的性能问题,因此无论如何您可能只需要硬件。
你不应该在新项目中使用传统的Direct3D9或Direct3D9Ex。它主要是在较新版本的Windows上模拟的,有很多奇怪的行为,而且到目前为止已经有将近20年的历史了。Windows 8.x或Windows 10上不支持Direct3D 9调试设备。你应该考虑将Direct3D 11作为DirectX新手开发人员的更好起点。

qybjjes1

qybjjes12#

进行以下代码更改

WNDCLASS wc = { };

wc.lpfnWndProc = MsgProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;

这解决了我的问题

相关问题