Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (2 posts)

D3D10Blob returns NULL

Last post 12/4/2015 5:13 PM by Charybdis. 1 replies.
  • 12/1/2015 9:26 PM

    D3D10Blob returns NULL

    I have this weird error and can't find how to fix it. I'm trying to make a vertex and pixel shader but when I'm calling them with CreateVertexShader and CreatePixelShader it return NULL. I have set my shader type to fx and and my shader model to 5_0. I'm using Visual Studio 2015 on windows 10


    When it gets created:


    ID3D11Buffer* TriangleVertBuffer;
    ID3D11VertexShader* VS;
    ID3D11PixelShader* PS;
    ID3D10Blob *VS_Buffer;
    ID3D10Blob *PS_Buffer;
    ID3D11InputLayout* VertLayout;

    When I'm calling them:


    //Compile Shaders from shader file
    hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "VS", "Vs_5_0", 0, 0, &VS_Buffer, 0);
    hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "PS", "Ps_5_0", 0, 0, &PS_Buffer, 0);


    //Create shader objects
    hr = D3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS);
    hr = D3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS);
    My Effects.fx class


    float4 VS(float4 inPos : POSITION) : SV_POSITION
    {
        return inPos;
    }


    float4 PS() : SV_TARGET
    {

        return float4(0.0f, 0.0f, 1.0f, 1.0f);
    }

    When I'm running it, it doesn't give an error but just a break point


    Exception thrown at 0x00007FF71F191AC4 in AzuraEngine.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

    and the debug says:


    VS_Buffer 0x0000000000000000 ID3D10Blob *

    &PS_Buffer 0x00007ff71f19f1f0 {AzuraEngine.exe!ID3D10Blob *PS_Buffer} {0x0000000000000000 } ID3D10Blob * *

    &VS 0x00007ff71f19f1d8 {AzuraEngine.exe!ID3D11VertexShader *VS} {0x0000000000000000 } ID3D11VertexShader * * D3DCompileFromFile 0x00007ff71f192950 {AzuraEngine.exe!D3DCompileFromFile} void *

    D3d11Device 0x000000c9ab0c78c0 ID3D11Device * hr 0x8876086c HRESULT

    source script:


    #pragma comment(lib, "d3d11.lib")
    #pragma comment(lib, "d3d10.lib")
    #pragma comment(lib, "D3DCompiler.lib")


    #include <Windows.h>
    #include <d3d11.h>
    #include <d3d10.h>
    #include <DirectXMath.h>
    #include <d3dcompiler.h>


    using namespace DirectX;


    bool InitScene();

    HRESULT hr;

    ID3D11Device* D3d11Device;


    //Creating all variables to the shader

    ID3D11Buffer* TriangleVertBuffer;

    ID3D11VertexShader* VS;

    ID3D11PixelShader* PS;

    ID3D10Blob *VS_Buffer;

    ID3D10Blob *PS_Buffer;

    ID3D11InputLayout* VertLayout;


    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

    {

        if (!InitScene())

        {

            return 0;

        }


        return 0;

    }


    bool InitScene()

    {

        //Compile shader from file

        hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "VS", "Vs_5_0", 0, 0, &VS_Buffer, 0);

        hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "PS", "Ps_5_0", 0, 0, &PS_Buffer, 0);


        //Creating Verex and Pixel shader

        hr = D3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS);

        hr = D3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS);


        return true;

    }

  • 12/4/2015 5:13 PM In reply to

    Re: D3D10Blob returns NULL

    Answer
    Reply Quote
    Already answered this question on MSDN.

    The profile strings are case sensitive:

    hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "VS""vs_5_0", 0, 0, &VS_Buffer, 0);  
    if ( FAILED(hr) ) ...  
     
    hr = D3DCompileFromFile(L"Effects.fx", 0, 0, "PS""ps_5_0", 0, 0, &PS_Buffer, 0);  
    if ( FAILED(hr) ) ... 

    Once you fix this, your repro fails because you never created D3d11Device.

    Be sure to check the return value of all functions that return HRESULT using the SUCCEEDED() macro, the FAILED() macro, or the DX::ThrowIfFailed() helper. If it is safe to ignore the return value, it will return void. See Error Handling in COM.
Page 1 of 1 (2 posts) Previous Discussion Next Discussion