Click here to Skip to main content
15,885,546 members

CreatePixelShader access violation

IDominator asked:

Open original thread
hello folks,

I keep getting an access violation exception when I create a pixelshader.

Here's the code:

C++
    HRESULT result;
ID3D10Blob* errorMessage;
ID3D10Blob* vertexShaderBuffer;
ID3D10Blob* pixelShaderBuffer;
D3D11_INPUT_ELEMENT_DESC polygonLayout[2];
unsigned int numElements;
D3D11_BUFFER_DESC matrixBufferDesc;

// Initialize the pointers this function will use to null.
errorMessage = 0;
vertexShaderBuffer = 0;
pixelShaderBuffer = 0;

result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "VSTex", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL,
                   &vertexShaderBuffer, &errorMessage, NULL);

if(FAILED(result))
{
    // If the shader failed to compile it should have writen something to the error message.
    if(errorMessage)
    {
        OutputShaderErrorMessage(errorMessage, hwnd, vsFilename);
    }
    // If there was nothing in the error message then it simply could not find the shader file itself.
    else
    {
        MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
    }

    return false;
}

// Compile the pixel shader code.
result = D3DX11CompileFromFile(psFilename, NULL, NULL, "PSTex", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL,
                   &pixelShaderBuffer, &errorMessage, NULL);
if(FAILED(result))
{
    // If the shader failed to compile it should have writen something to the error message.
    if(errorMessage)
    {
        OutputShaderErrorMessage(errorMessage, hwnd, psFilename);
    }
    // If there was nothing in the error message then it simply could not find the file itself.
    else
    {
        MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
    }

    return false;
}
// Create the vertex shader from the buffer.
result = device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &m_vertexShader); // No access violation here
if(FAILED(result))
{
    return false;
}
// Create the pixel shader from the buffer.
result = device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, &m_pixelShader);  // Here it comes
if(FAILED(result))
{
    return false;
}


I also checked if pixelShaderBuffer is still a nullpointer but it isn't and the buffersize is a non zero value.
I hope someone can help me. I also wish you a great valentine's day.
Tags: C++, DirectX, HLSL

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900