Programming is not a "play a psychic and guess the errors without checking" game!
returns a HRESULT value that tells the error reason if one occurred. Why make life hard on yourself (and the forum posters) and try to guess the error, when you can actually just ask what it was?
2. You ask D3DX11CompileFromFile to create you the blobs VS and PS. Why do you blindly trust it to do so? I don't think anyone loves Microsoft that much to believe their code is bug-free! You should check their end of the deal, namely, test that the function assigned to VS and PS, and that it's non-null:
ID3D10Blob *VS = 0;
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, 0, 0);
printf("D3DX11CompileFromFile failed to generate ID3D10Blob!\n");
clean up and abort;
3. Do you really trust Microsoft enough that even if the function manages to return you a valid blob, that it actually contains anything?
if (VS->GetBufferPointer() == 0 || VS->GetBufferSize() == 0)
printf("Error: Generated shader blob was empty!\n");
clean up and return;
4. Do you trust the CreateVertex/PixelShader
function to always succeed? It also returns a HRESULT.
5. Do you trust the outputted pVS/pPS pointers to be valid?
I recommend you first make your program print out "Error: The file shaders.hlsl was not found!" and benignly failing before actually trying to locate why you fail to load it. The file shaders.hlsl should contain your HLSL shader program code. You need to write it yourself (or copy from whatever tutorial/sample you're following). When dealing with relative paths, using _getcwd
to double-check the current working directory is helpful to diagnose where exactly the relative path is being looked at.
Edited by clb, 02 October 2012 - 07:54 AM.