Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:06:27+00:00 2026-06-15T04:06:27+00:00

I have a Windows Phone 8 C#/XAML project with DirectX component. I’m trying to

  • 0

I have a Windows Phone 8 C#/XAML project with DirectX component. I’m trying to rendering some particles. I create a vertex buffer, which I saw it go into the function to create, but when it gets to an update vertex buffer, the buffer is NULL. I have not released the buffers yet. Do you know why this will happen? Does any of the output messages help? Thanks.

Printouts and errors on my Output Window:

'TaskHost.exe' (Win32): Loaded '\Device\HarddiskVolume4\Windows\System32\d3d11_1SDKLayers.dll'. Cannot find or open the PDB file.
D3D11 WARNING: ID3D11Texture2D::SetPrivateData: Existing private data of same name with different size found! [ STATE_SETTING WARNING #55: SETPRIVATEDATA_CHANGINGPARAMS]
Create vertex buffer
D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.  [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET]
The thread 0xb64 has exited with code 0 (0x0).
m_vertexBuffer is null
D3D11 WARNING: ID3D11DeviceContext::DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.  [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET]
m_vertexBuffer is null

In CreateDeviceResources, I call CreateVertexShader, CreateInputLayout, CreatePixelShader, CreateBuffer. Then I get to creating the sampler and vertex buffer, code below:

    auto createCubeTask = (createPSTask && createVSTask).then([this] () {

        // Create a texture sampler state description.
        D3D11_SAMPLER_DESC samplerDesc;
        samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
        samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
        samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
        samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
        samplerDesc.MipLODBias = 0.0f;
        samplerDesc.MaxAnisotropy = 1;
        samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
        samplerDesc.BorderColor[0] = 0;
        samplerDesc.BorderColor[1] = 0;
        samplerDesc.BorderColor[2] = 0;
        samplerDesc.BorderColor[3] = 0;
        samplerDesc.MinLOD = 0;
        samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

        // Create the texture sampler state.
        HRESULT result = m_d3dDevice->CreateSamplerState(&samplerDesc, &m_sampleState);
        if(FAILED(result))
        {
            OutputDebugString(L"Can't CreateSamplerState");
        }

        //InitParticleSystem();

        // Set the maximum number of vertices in the vertex array.
        m_vertexCount = m_maxParticles * 6;

        // Set the maximum number of indices in the index array.
        m_indexCount = m_vertexCount;

        // Create the vertex array for the particles that will be rendered.
        m_vertices = new VertexType[m_vertexCount];
        if(!m_vertices)
        {
            OutputDebugString(L"Can't create the vertex array for the particles that will be rendered.");
        }
        else
        {
            // Initialize vertex array to zeros at first.
            int sizeOfVertexType = sizeof(VertexType);
            int totalSizeVertex = sizeOfVertexType * m_vertexCount;
            memset(m_vertices, 0, totalSizeVertex);
            D3D11_SUBRESOURCE_DATA vertexBufferData = {0};
            vertexBufferData.pSysMem = m_vertices;
            vertexBufferData.SysMemPitch = 0;
            vertexBufferData.SysMemSlicePitch = 0;

            int sizeOfMVertices = sizeof(m_vertices);
            CD3D11_BUFFER_DESC vertexBufferDesc(
                totalSizeVertex,            // byteWidth
                D3D11_BIND_VERTEX_BUFFER,   // bindFlags
                D3D11_USAGE_DYNAMIC,        // D3D11_USAGE usage = D3D11_USAGE_DEFAULT
                D3D11_CPU_ACCESS_WRITE,     // cpuaccessFlags
                0,                          // miscFlags
                0                           // structureByteStride
                );

            OutputDebugString(L"Create vertex buffer\n");

            DX::ThrowIfFailed(
                m_d3dDevice->CreateBuffer(
                    &vertexBufferDesc,
                    &vertexBufferData,
                    &m_vertexBuffer
                    )
                );
        }


        unsigned long* indices = new unsigned long[m_indexCount];
        if(!indices)
        {
            OutputDebugString(L"Can't create the index array.");
        }
        else
        {
            // Initialize the index array.
            for(int i=0; i<m_indexCount; i++)
            {
                indices[i] = i;
            }

            // Set up the description of the static index buffer.
            // Create the index array.
            D3D11_BUFFER_DESC indexBufferDesc;
            indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
            indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount;
            indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
            indexBufferDesc.CPUAccessFlags = 0;
            indexBufferDesc.MiscFlags = 0;
            indexBufferDesc.StructureByteStride = 0;

            // Give the subresource structure a pointer to the index data.
            D3D11_SUBRESOURCE_DATA indexData;       
            indexData.pSysMem = indices;
            indexData.SysMemPitch = 0;
            indexData.SysMemSlicePitch = 0;

            // Create the index buffer.
            DX::ThrowIfFailed(
                m_d3dDevice->CreateBuffer(
                    &indexBufferDesc,
                    &indexData,
                    &m_indexBuffer
                    )
                );

            // Release the index array since it is no longer needed.
            delete [] indices;
            indices = 0;

        }

    });

    createCubeTask.then([this] () {     
        m_loadingComplete = true;
    });
}

My vertex is position, tex, and color:

struct VertexType
{
    DirectX::XMFLOAT3 position;
    DirectX::XMFLOAT2 texture;
    DirectX::XMFLOAT4 color;

};

Microsoft::WRL::ComPtr<ID3D11SamplerState> m_sampleState;
VertexType* m_vertices;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;


const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR",    0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

VertexShader.HLSL:

cbuffer ModelViewProjectionConstantBuffer : register(b0)
{
    matrix model;
    matrix view;
    matrix projection;
};

struct VertexInputType
{
    float4 position : POSITION;
    float2 tex : TEXCOORD0;
    float4 color : COLOR;
};

struct PixelInputType
{
    float4 position : SV_POSITION;
    float2 tex : TEXCOORD0;
    float4 color : COLOR;
};

PixelInputType main(VertexInputType input)
{
    PixelInputType output;    
    // Change the position vector to be 4 units for proper matrix calculations.
    input.position.w = 1.0f;
    // Calculate the position of the vertex against the world, view, and projection matrices.
    output.position = mul(input.position, model);
    output.position = mul(output.position, view);
    output.position = mul(output.position, projection);

    // Store the texture coordinates for the pixel shader.
    output.tex = input.tex;

    // Store the particle color for the pixel shader. 
    output.color = input.color;

    return output;
}

After the call to: m_d3dDevice->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &m_vertexBuffer) the m_vertexBuffer is not null.

But when I get to my Update() function, m_vertexBuffer is NULL!

D3D11_MAPPED_SUBRESOURCE mappedResource;    
if (m_vertexBuffer == nullptr)
{
    OutputDebugString(L"m_vertexBuffer is null\n");
}
else
{

    // Lock the vertex buffer.
    DX::ThrowIfFailed(m_d3dContext->Map(m_vertexBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource));

    // Get a pointer to the data in the vertex buffer.
    VertexType * verticesPtr = (VertexType*)mappedResource.pData;

    //// Copy the data into the vertex buffer.
    int sizeOfVertices = sizeof(VertexType) * m_vertexCount;
    memcpy(verticesPtr, (void*)m_vertices, sizeOfVertices);

    //// Unlock the vertex buffer.
    m_d3dContext->Unmap(m_vertexBuffer.Get(), 0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:06:28+00:00Added an answer on June 15, 2026 at 4:06 am

    I was making the incorrect call on m_vertexBuffer when I go Render it.
    This fixes the error with the m_vertexBuffer being null.

    Previous:

    m_d3dContext.Get()->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
    

    Fix:

    m_d3dContext.Get()->IASetVertexBuffers(0, 1, m_vertexBuffer.GetAddressOf(), &stride, &offset);
    

    It doesn’t fix the error with the sampler states though:

    DrawIndexed: The Pixel Shader unit expects a Sampler to be set at Slot
    0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Windows Phone project I have the following scenario: The user types some
I have a sample windows phone 7 project where I test some MVVM stuff,
I have a windows phone 7 app with some xaml that looks like: <Grid
I have a Windows Phone 7.5/Silverlight app. I have some code that I duplicate
I have to create a Windows Phone 7 app as part of a research
I'm trying to set the background to a windows phone page in Xaml. I'm
I'm developing a Windows Phone application . I have defined this on App.xaml: <nav:UriMapping
Some controls in Windows Phone 7 have touchable area around, if you touch not
I have a XAML page in a separate Windows Phone class library. The library
In a Windows Phone 7 project I'm using XAML that looks like this; <phone:PhoneApplicationPage.Resources>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.