0

So I was messing around with some text handling to go with DirectXTK's text rendering and I think I might have "pissed off" visual studio. After getting some errors because I tried to make it work with arrays out of bounds it gave me errors, and I don't know if I simply got the error too many times or if I by mistake tried to continue running the program beyond the error but now I get an error (the same I think) in a completly different class.

HRESULT hr;
wchar_t VSFilepath[250] = L"";
wchar_t PSFilepath[250] = L"";

wchar_t SVSFilepath[250] = L"";
wchar_t SPSFilepath[250] = L"";

wcscat_s(VSFilepath, directory);
wcscat_s(VSFilepath, L"\\Shaders\\Player\\PlayerVertexShader.hlsl");
wcscat_s(PSFilepath, directory);
wcscat_s(PSFilepath, L"\\Shaders\\Player\\PlayerPixelShader.hlsl");

//create vertex shader
ID3DBlob* pVS = nullptr;
hr = D3DCompileFromFile(VSFilepath,
                        nullptr,
                        D3D_COMPILE_STANDARD_FILE_INCLUDE,
                        "VS_main",
                        "vs_5_0",
                        0,
                        NULL,
                        &pVS,
                        nullptr);

hr = gDevice->CreateVertexShader(pVS->GetBufferPointer(),
                                 pVS->GetBufferSize(),
                                 nullptr,
                                 &playerVertexShader);

//create input layout (verified using vertex shader)
D3D11_INPUT_ELEMENT_DESC inputDesc[] =
{
    {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
    {"NORMAL",   0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0}, 
};
hr = gDevice->CreateInputLayout(inputDesc,
                                ARRAYSIZE(inputDesc),
                                pVS->GetBufferPointer(),
                                pVS->GetBufferSize(),
                                &playerVertexLayout);
pVS->Release();

//create pixel shader
ID3DBlob* pPS = nullptr;
hr = D3DCompileFromFile(PSFilepath,
                        nullptr,
                        D3D_COMPILE_STANDARD_FILE_INCLUDE,
                        "PS_main",
                        "ps_5_0",
                        0,
                        NULL,
                        &pPS,
                        nullptr);

hr = gDevice->CreatePixelShader(pPS->GetBufferPointer(),
                                pPS->GetBufferSize(),
                                nullptr,
                                &playerPixelShader);
pPS->Release();

By stepping through the program I have come to the following conclusion:

After I use a create shader function, CreateVertexShader for example, the next time I try to use D3DCompileFromFile the program stops and with "First-chance exception at 0x772BDBB7 in game.exe: 0xC0000008: An invalid handle was specified."

It doesn't matter if I try to comment out the CreateVertexShader, sure it can create the next pixelshader but the next D3DCompileFromFile gives me the same error, and all hr results are S_OK.

The thing is that his code has worked probably a hundred times before this and I haven't changed anything related to it, so I am extremely confused as to what has happened.

user4581301
  • 33,082
  • 7
  • 33
  • 54
Gamewolf3000
  • 63
  • 2
  • 8
  • 2
    Error checking is not optional, you *must* verify the `hr` return values. – Hans Passant Aug 05 '15 at 02:13
  • @HansPassant I'm not sure if I understand what you mean, as I wrote in the question, I have checked the hr values as I stepped through the code, they all return S_OK up until the second D3DCompileFromFile where the program crashes on attempting to execute it, thus there is no return value from that one. – Gamewolf3000 Aug 05 '15 at 12:16
  • You should have code that checks the return values. You can't depend on the debugger to detect them reliably. – Ross Ridge Aug 05 '15 at 19:50
  • Have you tried rebuilding the whole solution? – mock_blatt Aug 05 '15 at 22:47

0 Answers0