DirectX 9 着色器未显示错误

DirectX 9 Shader not displaying errors

本文关键字:显示 错误 DirectX      更新时间:2023-10-16

我正在研究DirectX9和着色器,我正在使用以下代码:

D3DXCreateEffectFromFile(DirectX::device, "shader.fx", 0, 0, D3DXSHADER_DEBUG, 0, &effect, &errors);
if(errors){
    MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0);
}

问题是,我知道我的着色器中存在错误/错误,但它没有弹出一个错误框来说明错误是什么......有人可以告诉我我做错了什么吗?

我最近升级到 DirectX 11,这就是我现在正在做的事情。 它应该在DX9中成立。

char *compileErrors;
unsigned long bufferSize, i;
std::ofstream fout;

//get a pointer to the error message text buffer
compileErrors = (char*)(errorMessage->GetBufferPointer());
//get the length of the message
bufferSize = errorMessage->GetBufferSize();
//open a file to write the error message to
fout.open("shader-error.txt");
//write out the error message
for(i=0; i<bufferSize; i++)
{
    fout << compileErrors[i];
}
//close the file
fout.close();
//release the error message
errorMessage->Release();
errorMessage = nullptr; //or NULL, depending on your compiler
//pop a message up on the screen to notify the user to check the text file for compile errors
MessageBox(hwnd, "Error compiling shader.  Check shader-error.txt for message.", (LPCSTR)shaderFilename, MB_OK);
//shaderFilename and hwnd not defined in this code.  pass as a function parameter or something

此外,如果您已经删除了创建的第一个窗口(例如,在完成所有初始化后删除的初始窗口),则不会显示第一个参数为 NULLMessageBox。 无需在运行时调用DestroyWindow,只需隐藏窗口并在程序退出时释放它。 隐藏窗口的代码:ShowWindow(splashWnd, WS_HIDE);